zoukankan      html  css  js  c++  java
  • Python爬虫之 selenium 设置 PhantomJS header请求头

    from selenium import webdriver
    from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    headers = {
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
        'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0',
        'Connection': 'keep-alive'
    }
    cap = DesiredCapabilities.PHANTOMJS
    for key, value in headers.items():
        cap['phantomjs.page.customHeaders.{}'.format(key)] = value
    browser = webdriver.PhantomJS(desired_capabilities=cap)
    browser.get("http://www.你的链接.com")
    browser.quit()

    打印看看 cap字典里是啥就很清楚了  ↓↓↓

    {'browserName': 'phantomjs',
     'version': '',
     'platform': 'ANY',
     'javascriptEnabled': True,
     'phantomjs.page.customHeaders.Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
     'phantomjs.page.customHeaders.Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
     'phantomjs.page.customHeaders.User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0',
     'phantomjs.page.customHeaders.Connection': 'keep-alive'}
  • 相关阅读:
    C++调用web服务(java事例供参考)
    ASP.NET1.1与2.0如何引入MagicAjax (转载自http://hi.baidu.com/zzticzh)
    爱,在世界末日时
    Why Google Chrome is Multiprocess Architecture
    Chrome
    Code Reuse in Google Chrome
    Google V8 JavaScrit 研究(1)
    第一篇文章
    User Experience
    WPF
  • 原文地址:https://www.cnblogs.com/zrzm/p/13324741.html
Copyright © 2011-2022 走看看