注册
登录
 文档中心 产品介绍 开发指南 API接口 代码样例 使用帮助
文档中心 / 代码样例 / Python-Selenium /
Python-Selenium使用PhantomJS调用Http代理IP的代码样例
站大爷 官方 2024-01-20 1447 浏览

温馨提示:

1.  此样例为基于用户名密码+无界面方式使用 Selenium + PhantomJS认证代理IP

2.  运行环境要求python2/3 + selenium + PhantomJS + Windows/Linux/macOS

3.  推荐使用2.1.1版PhantomJS

4.  ${executable_path}:您本机PhantomJS驱动存放路径,如:"C:\phantomjs-2.1.1-windows\bin\phantomjs.exe"


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=http',
	'--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()


立即注册站大爷用户,免费试用全部产品
立即注册站大爷用户,免费试用全部产品