Reputation:
I have run the following code below twice. Once with the headless argument and once without. I checked the screenshots and the website seems to behave differently when ran headless. The main difference is that the second bar of search criteria does not exist. I have attached the screenshots below. How can I deal with this?
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
url = 'https://www.glassdoor.com/Job/jobs.htm?suggestCount=0&suggestChosen=false&clickSource=searchBtn&typedKeyword=&locT=C&locId=1147401&jobType=&context=Jobs&sc.keyword=what&dropdown=0'
chromeoption = Options()
chromeoption.add_argument('--headless')
chromeoption.add_argument('--window-size=1300,700')
browser = webdriver.Chrome(options=chromeoption)
browser.get(url)
time.sleep(5)
browser.save_screenshot(file_location)
Upvotes: 0
Views: 1511
Reputation: 19949
chromeoption.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36")
browser = webdriver.Chrome(options=chromeoption )
Try adding user-agent, when running headess user agent wil be send as headless chrome which allows website to know you are running headless. FOr this reason website may behave differently
Upvotes: 1