My friends and I are trying to get into a website using selenium headless, but we keep getting blocked by their bot and are asked to solve a captcha. Our code currently works when selenium is not headless, so we think it has something to do with the window size that's sent to the website. We tried manually setting the window size through the chromedriver options to 1920x1080, but we are still getting blocked by the site. The window size is set correctly since running the command print(driver.get_window_size())
returns the size that I set, so there must be some other test that the website is running to check if selenium is headless.
Asked
Active
Viewed 7,246 times
1

Avi Komarlingam
- 47
- 1
- 5
-
1Try running with xvfb-run instead of headless. – pguardiario Apr 30 '20 at 01:39
2 Answers
2
The site is obviously checking for headless browsers and then denying them access. Here's an article on avoiding detection: Making Chrome Headless Undetectable
Generally the speed it runs at is what is detectable. In a legit environment that speed is something you'd want. If you're trying to automate you may need to put some waits in between the actions to simulate a user.

AzyCrw4282
- 7,222
- 5
- 19
- 35
-
We're asked to solve a captcha right after getting onto the website without making any other actions, so the problem isn't speed. Is there any way we can modify the chromedriver options so we don't need to integrate a js file? – Avi Komarlingam Apr 26 '20 at 23:51
-
The fact that `captcha` is detected only on headless suggest that it must be to do with some pre-defined Js varaibles. So you can try to alter that, see [this here on how to do it](https://stackoverflow.com/a/41220267/6505847) – AzyCrw4282 Apr 27 '20 at 03:25
-
-
I looked at your answer but I can't find any js file to modify (I'm on a windows machine) and opening chromedriver.exe in a hex editor still gave me gibberish. – Avi Komarlingam Apr 28 '20 at 13:00
-3
The best way to make it undetectable is to add time frame.
Import time
time.sleep(2)
It generally works.

Devilz Kingz
- 13
- 3