Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in DevOps and Agile by (19.7k points)

According to this, it is possible now to modify headers. Atm, I need to modify Accept-Language in PhantomJS webdriver. This code doesn't work

DesiredCapabilities.PHANTOMJS[''] = 'ru-RU'

driver = webdriver.PhantomJS()

Is it possible somehow to configure Phantomjs to send my header? I don't care where: inside ghostdriver, phantomjs or phantomjs-webdriver.

1 Answer

0 votes
by (62.9k points)

The latest version (2.1) of PhantomJS was released January 23, 2016, hence, the pull request is merged January 23, 2016.

If you are using the 2.1 version of PhantomJS, custom headers will not work.

You have to build phantomjs yourself or wait until phantomjs merge ghost driver changes and release a new version.

Clone PhantomJS repository

Clone ghostdriver repository

copy ghostdriver/src/* to phantomjs/src/ghostdriver recursively

build phantomjs

Using newly build phantomjs I got the following result:

from selenium import webdriver webdriver.DesiredCapabilities.PHANTOMJS[''] = 'ru-RU' driver = webdriver.PhantomJS() driver.get('') print(driver.page_source)

... { "headers": { "Connection": "close", "Host": "", "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" } ...

Browse Categories