温馨提示:
1. 基于终端IP授权方式使用Selenium+Chrome认证代理
2. 运行环境要求python2/3 + selenium + Chrome + Chromedriver + Windows/Linux/macOS
3. 注意chromedriver版本要和Chrome版本对应
4. selenium不是python原生库,需要安装才能使用:pip install selenium
5. ${chromedriver_path}:您本机chromedriver驱动存放路径,如:"C:\chromedriver.exe"
6. 代码样例中的代理IP和端口均为虚构,请通过ipip9的API提取链接获取代理IP后使用,避免报错
7. Chrome 本身不支持 SOCKS 认证,因此Selenium也无法支持,"用户名+密码"授权请使用 Selenium + PhantomJS进行认证。
参考样例
from selenium import webdriver import time options = webdriver.ChromeOptions() options.add_argument('--proxy-server=socks5://${168.168.168.168:88888}') # ${chromedriver_path}: chromedriver驱动存放路径 driver=webdriver.Chrome(executable_path="${chromedriver_path}", options=options) driver.get("https://example.com") # 获取页面内容 print(driver.page_source) # 延迟3秒后关闭当前窗口如果是最后一个窗口则退出 time.sleep(3) driver.close()