How To Know If My Custom Http Headers Are Being Passed?
So, I have been struggling with passing custom HTTP header for some time now. I am creating a script (Python) to Open a URL with Custom headers like {'Referer': 'https://googl
Solution 1:
I solved the problem of passing the header by removing the Browsermob-proxy and instead using seleniumwire and use its driver._client.set_header_overrides(headers=dict_headers)
to override the default HTTP headers.
def automation():
headers = pd.read_excel('Database/header.xlsx')
data = pd.read_csv('Database/data.csv')
for i in range(0,headers.shape[0]):
dict_headers = {}
header = headers.loc[i]
dict_headers['Referer'] = header['Referrer']
dict_headers[header['Option']] = header['IP']
dict_headers['User-Agent'] = header['USERAGENT']
URL = 'xyz'
user_agent = "user-agent="+header['USERAGENT']
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(user_agent)
driver = webdriver.Chrome(
chrome_options=chrome_options,
executable_path='/home/.../chromedriver')
driver._client.set_header_overrides(headers=dict_headers)
datum = data.loc[i]
driver.get(URL)
driver.quit()
return None
automation()
Post a Comment for "How To Know If My Custom Http Headers Are Being Passed?"