
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+ 。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)