Selenium修改PhantomJS请求头(Headers)

♀尐吖头ヾ 提交于 2020-02-12 11:39:40

Selenium修改PhantomJS请求头(Headers)

 
复制代码
headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4',
    'Connection': 'keep-alive'
}
cap = DesiredCapabilities.PHANTOMJS.copy()//使用copy()防止修改原代码定义dict
for key, value in headers.items():
    cap['phantomjs.page.customHeaders.{}'.format(
        key)] = value
browser = webdriver.PhantomJS(desired_capabilities=cap)
复制代码

 

 
 
复制代码
headers = {
    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
    'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4',
    'Connection': 'keep-alive'
}
cap = DesiredCapabilities.PHANTOMJS.copy()//使用copy()防止修改原代码定义dict
for key, value in headers.items():
    cap['phantomjs.page.customHeaders.{}'.format(
        key)] = value
browser = webdriver.PhantomJS(desired_capabilities=cap)
复制代码

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!