示例代码
from selenium import webdriver
proxyHost = "dyn.horocn.com"
proxyPort = "50000"
# 隧道代理订单号
proxyUser = "xxx"
# 密码,在用户中心 -- 隧道代理订单页面可查询到
proxyPass = "xxx"
service_args = [
"--proxy-type=http",
"--proxy=%(host)s:%(port)s" % {
"host" : proxyHost,
"port" : proxyPort,
},
"--proxy-auth=%(user)s:%(pass)s" % {
"user" : proxyUser,
"pass" : proxyPass,
},
]
# 目标地址,将下面的地址改为你要采集的地址即可
targetUrl = "https://www.baidu.com"
phantomjs_path = "/path/to/bin/phantomjs"
driver = webdriver.PhantomJS(executable_path=phantomjs_path, service_args=service_args)
driver.get(targetUrl)
print(driver.title)
print(driver.page_source.encode("utf-8"))
driver.quit()
转载请注明