Phantomjs Selenium WebDriver中的自定义标头

Phantomjs Selenium WebDriver中的自定义标头,第1张

Phantomjs Selenium WebDriver中的自定义标头

PhantomJS
的最新版本(1.9.1)是2013年5月5日发布。拉取请求已合并2013年6月23日。

如果您使用的PhantomJS 1.9.1版本,自定义标头将不起作用。

您必须自己构建phantomjs或等到phantomjs合并ghostdriver更改并发布新版本。

  • 克隆PhantomJS存储库
  • 克隆ghostdriver存储库
  • 递归地将ghostdriver / src / *复制到phantomjs / src / ghostdriver
  • 构建phantomjs

使用新建的phantomjs,我得到以下结果:

from selenium import webdriverwebdriver.DesiredCapabilities.PHANTOMJS['phantomjs.page.customHeaders.Accept-Language'] = 'ru-RU'driver = webdriver.PhantomJS()driver.get('http://httpbin.org/headers')print(driver.page_source)

...{  "headers": {    "Connection": "close",    "Host": "httpbin.org",    "Accept-Encoding": "gzip",    "Accept-Language": "ru-RU",    "User-Agent": "Mozilla/5.0 (Unknown; Linux i686) AppleWebKit/534.34 (KHTML, like Gecko) PhantomJS/1.10.0 (development) Safari/534.34",    "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"  } ...
更新

使用PhantomJS 1.9.2+



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5125361.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-17
下一篇2022-11-17

发表评论

登录后才能评论

评论列表(0条)

    保存