mherrmann/helium

How to add Custom Headers to helium ?

Opened this issue · 2 comments

Hi so i have the followinng code, i can change the user-agent jsut fine, but how to add additional header options ?

from selenium.webdriver import FirefoxOptions
from helium import*


useragent = "Mozilla/5.0 (X11; Linux x86_64; rv:104.0) Gecko/20100101 Firefox/104.0"

options = FirefoxOptions()

options.set_preference("general.useragent.override",useragent)


s = start_firefox("https://www.instagram.com", headless=False, options=options,)

time.sleep(15)

kill_browser()

i want to add the following full headers.. How can I do that ? Thanks

headers = {"Accept":	"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
"Accept-Encoding"	: "gzip, deflate, br",
"Accept-Language"	: "en-GB,en;q=0.5",
"Connection"	: "keep-alive",
"Host"	: "data.similarweb.com",
"Sec-Fetch-Dest"	: "document",
"Sec-Fetch-Mode"	: "navigate",
"Sec-Fetch-Site"	: "none",
"Sec-Fetch-User"	: "?1",
"Upgrade-Insecure-Requests"	: "1",
"User-Agent"	: "Mozilla/5.0 (X11; Linux x86_64; rv:103.0) Gecko/20100101 Firefox/103.0"}

Why do you need to add headers like this? Are you trying to do API testing?

Why do you need to add headers like this? Are you trying to do API testing?

Hi thanks for the reply.

Some websites block if proper headers are not there. I am web scraping many retail websites.

I was web scraping just fine.. but could not open Nordstrom.

So that's why want to ask how to add custom headers to the script.

Nordstrom opens fine while regular browsing.. but not with helium/selenium

Thanks