Python-Selenium使用PhantomJS调用Socks5代理IP的代码样例
站大爷
官方
2024-01-20
1443 浏览
温馨提示:
1. 基于用户名+密码授权使用 Selenium + PhantomJS认证代理
2. 运行环境要求python2/3 + selenium + PhantomJS + Windows/Linux/macOS
3. ${executable_path}:您本机PhantomJS驱动存放路径,如:"C:\phantomjs-2.1.1-windows\bin\phantomjs.exe"from
4. 推荐使用2.1.1版PhantomJS
from selenium import webdriver
import time
#先下载phantomjs包文件,再填入phantomjs.exe的路径 (路径不要包含中文, 下载地址:https://mirrors.huaweicloud.com/phantomjs/)
executable_path='${executable_path}'
service_args=[
'--proxy=host:168.168.168.168:8888', #此处替换您的代理ip
'--proxy-type=socks5',
'--proxy-auth=username:password' #用户名密码
]
driver=webdriver.PhantomJS(service_args=service_args,executable_path=executable_path)
driver.get('https://example.com')
print(driver.page_source)
time.sleep(3)
driver.close()