PhantomJS调用HTTP代理
Python-Selenium使用PhantomJS调用Http代理IP的代码样例
温馨提示:
此样例为基于用户名密码+无界面方式使用 Selenium + PhantomJS认证代理IP
运行环境要求python2/3 + selenium + PhantomJS + Windows/Linux/macOS
推荐使用2.1.1版PhantomJS
${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('http://api.91http.com/v1/tool/get-my-ip')
print(driver.page_source)
time.sleep(3)
driver.close()
最后修改时间: 4 个月前