gpt4 book ai didi

python - 使用 PhantomJS 进行代理身份验证

转载 作者:太空宇宙 更新时间:2023-11-04 05:05:15 25 4
gpt4 key购买 nike

我正在尝试使用 PhantomJS 和 Python 对代理服务器进行身份验证。这是我的

service_args = [
'--proxy=http://us-ny.proxymesh.com:31280',
'--proxy-type=http',

]

authentication_token = "Basic " + base64.b64encode(b'username:pass')

capa = DesiredCapabilities.PHANTOMJS
capa['phantomjs.page.customHeaders.Proxy-Authorization'] = authentication_token

driver = webdriver.PhantomJS( desired_capabilities=capa, service_args=service_args)

driver.get(request.url)
body = driver.page_source
print body

这只会打印出来

<html><head></head><body></body></html>

澄清一下,当我将我的 IP 添加到代理服务器时,这会起作用 - 已验证的 IP 和主机名,但我需要它在没有它的情况下工作

最佳答案

这是我的有效解决方案。我最终需要在 service_args 和 proxy-auth header 中传递凭据。

service_args = [
"--ignore-ssl-errors=true",
"--ssl-protocol=any",
"--proxy={}".format(proxy),
"--proxy-type=http",
]

caps = DesiredCapabilities.PHANTOMJS

authentication_token = "Basic " + base64.b64encode(b'{}:{}'.format(username, password))

caps['phantomjs.page.customHeaders.Proxy-Authorization'] = authentication_token

self.driver = webdriver.PhantomJS(
service_args=service_args,
desired_capabilities=caps,
executable_path="./phantomjs-2.1.1-linux-x86_64/bin/phantomjs")

代理结构定义为http://username:password@domain:port

我不知道你为什么要重复凭据。我猜测第一个身份验证参数不会作为 header 传递给代理,因此您需要手动执行这两项操作。

关于python - 使用 PhantomJS 进行代理身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44676597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com