Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ozen
Last active September 6, 2021 05:12
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save ozen/e24c4d40b53a774d9b36 to your computer and use it in GitHub Desktop.
Save ozen/e24c4d40b53a774d9b36 to your computer and use it in GitHub Desktop.
How to set request headers when using Selenium Python with PhantomJS driver
from selenium import webdriver
from selenium.webdriver import DesiredCapabilities
desired_capabilities = DesiredCapabilities.PHANTOMJS.copy()
desired_capabilities['phantomjs.page.customHeaders.User-Agent'] = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) ' \
'AppleWebKit/537.36 (KHTML, like Gecko) ' \
'Chrome/39.0.2171.95 Safari/537.36'
driver = webdriver.PhantomJS(desired_capabilities=desired_capabilities)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment