zoukankan      html  css  js  c++  java
  • selenium+headless+proxy 的出错

    之前的代码

    chromedriver_path = "存放webdriver的路径"
    
    options = Options()
    options.add_argument('--disable-gpu')
    options.add_argument('--no-sandbox')
    options.add_argument("disable-infobars")
    options.add_argument("--disable-notifications")
    options.add_argument('headless')
    # 设置代理
    options.add_argument("--proxy-server=http://" + ip_port)
    
    driver = webdriver.Chrome(options=options, executable_path=chromedriver_path)
    
    

    这种方式会得不到数据,的到的页面信息是这样的。

    
    
    

    解决方案1

    参考文献: https://cloud.tencent.com/developer/article/1567061

             options = webdriver.ChromeOptions()
            # 设置代理
            desired_capabilities = webdriver.DesiredCapabilities.INTERNETEXPLORER.copy()
            desired_capabilities['proxy'] = {
                "httpProxy": "http://121.9.199.31:26605",
                # "ftpProxy": self.proxy_ip,  # 代理ip是否支持这个协议
                # "sslProxy": self.proxy_ip,  # 代理ip是否支持这个协议
                "noProxy": None,
                "proxyType": "MANUAL",
                "class": "org.openqa.selenium.Proxy",
                "autodetect": False
            }
    
            # 使用无头模式
            options.add_argument('--disable-gpu')
            options.add_argument('--no-sandbox')
            options.add_argument("disable-infobars")
            options.add_argument("--disable-notifications")
            options.add_argument('headless')
            options.add_experimental_option("useAutomationExtension", False)
            options.add_experimental_option("excludeSwitches", ["enable-automation"])
    
            driver = webdriver.Chrome(chrome_options=options,
                                       executable_path=r'C:chromedriver.exe',
                                       desired_capabilities=desired_capabilities)
    
    
    
    

    解决方案2

    参考文献 :https://cloud.tencent.com/developer/article/1651263

    这种方式没有去现实。先记录下

  • 相关阅读:
    多选按钮CheckBox
    DatePicker和DataPickerDialog以及AutoCompleteTextView的基本使用方法
    Broadcast机制(二)
    广播机制(一)
    XML文件解析
    WIFI网络操作
    SQL Server Profiler工具
    SQL Server执行计划的理解
    SQL Server常用元数据函数
    SQL Server数学函数
  • 原文地址:https://www.cnblogs.com/xibanqiu/p/13716543.html
Copyright © 2011-2022 走看看