python proxy-auth中的phantomjs selenium无法正常工作
发布时间:2020-11-17 01:16:00 所属栏目:Python 来源:互联网
导读:我正在尝试使用selenium phantomjs设置webscraping的代理.我正在使用 python. 我在很多地方都看到phantomjs中存在一个bug,因为proxy-auth不起作用. from selenium.webdriver.common.proxy import *from selenium import webdriverfrom selenium.webdrive
我正在尝试使用selenium phantomjs设置webscraping的代理.我正在使用 python. 我在很多地方都看到phantomjs中存在一个bug,因为proxy-auth不起作用. from selenium.webdriver.common.proxy import * from selenium import webdriver from selenium.webdriver.common.by import By service_args = [ '--proxy=http://fr.proxymesh.com:31280','--proxy-auth=USER:PWD','--proxy-type=http',] driver = webdriver.PhantomJS(service_args=service_args) driver.get("https://www.google.com") print driver.page_source 代理网格建议使用以下代码:
但我不知道如何将其转换为python. 这就是我目前拥有的: from selenium import webdriver import base64 from selenium.webdriver.common.proxy import * from selenium import webdriver from selenium.webdriver.common.by import By service_args = [ '--proxy=http://fr.proxymesh.com:31280',] headers = { 'Proxy-Authorization': 'Basic ' + base64.b64encode('USERNAME:PASSWORD')} for key,value in enumerate(headers): webdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.{}'.format(key)] = value driver = webdriver.PhantomJS(service_args=service_args) driver.get("https://www.google.com") print driver.page_source 但它不起作用. 有关如何使其工作的任何建议? 解决方法我正在编译答案:How to correctly pass basic auth (every click) using Selenium and phantomjs webdriver 以及: base64.b64encode error from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities import base64 service_args = [ '--proxy=http://fr.proxymesh.com:31280',] authentication_token = "Basic " + base64.b64encode(b'username:password') capa = DesiredCapabilities.PHANTOMJS capa['phantomjs.page.customHeaders.Proxy-Authorization'] = authentication_token driver = webdriver.PhantomJS(desired_capabilities=capa,service_args=service_args) driver.get("http://...") (编辑:十堰站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- python – 根据上一个和下一个元素将元素插入到列表中
- version-control – 从hg存储库中删除二进制文件
- 在Django模板中使用前导下划线访问dict元素
- python – 跨多个链式函数的namedTuples定义
- 如何使用Python的ctypes和readinto读取包含数组的结构?
- python – 无法重现使用astropy获取的源之间的距离值
- python – WTForms SelectField没有正确地强制执行布尔值
- python – 如何在PyCharm中找到所有未使用的类的方法?
- python – SQLAlchemy:排除从查询中的子查询中获取的行
- database – Django:锁定表中的特定行