简体   繁体   中英

Detected on Headless Chrome Selenium

Im trying to scrape Amazon when running headless with a up to date UserAgent I am getting rate limited. When I # out the headless line I don't get detected or rate limited. Below is my code!

options = Options()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
options.add_experimental_option("useAutomationExtension", False)
#options.add_argument("--headless")
options.add_argument("--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36")
service = ChromeService(executable_path=ChromeDriverManager().install())
browser = webdriver.Chrome(service=service, options=options)
browser.get("https://www.amazon.com.au/Oculus-Quest-2-Virtual-Reality-Headset/dp/B08FSZ8QWH")
print(browser.page_source)

When I remove the # at options.add_argument("--headless") and I run the code I get a server busy line. Does anyone know of a fix?

To avoid detection using add the following argument through add_argument() as follows:

--disable-blink-features=AutomationControlled

Sample Code:

options = Options()
options.headless = True
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('excludeSwitches', ['enable-logging'])
options.add_experimental_option('useAutomationExtension', False)
options.add_argument('--disable-blink-features=AutomationControlled')
s = Service('C:\\BrowserDrivers\\chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
driver.get("https://www.amazon.com.au/Oculus-Quest-2-Virtual-Reality-Headset/dp/B08FSZ8QWH")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM