from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
url = 'http://www.baidu.com'
chromeOptions = webdriver.ChromeOptions()
dailiip = '--proxy-server=http://52.67.126.170:3129' # 代理ip的ip及其端口
chromeOptions.add_argument(dailiip)
driver_path = 'C:/Users/95/AppData/Local/Google/Chrome/Application/chromedriver.exe'
driver = webdriver.Chrome(executable_path=driver_path, chrome_options=chromeOptions)
# driver = webdriver.Chrome(executable_path=driver_path)
driver.maximize_window() # 窗口最大化
driver.get(url)
主要是用selenium来使用代理ip打开网页
使用注意:
1、电脑需安装谷歌浏览器,并下载好chromedriver.exe;
2、python安装好selenium库
确认自己是否使用代理ip的办法:最直观的就是看你的模拟浏览器是否打开了www.baidu.com;第二种办法就是打开http://httpbin.org/ip查看此时电脑上网使用的ip