I tried accessing a site with Selenium (with geckodriver) and it said I was blocked but I can access it manually with the Firefox Browser. So I compared the components of my
Refer to this issue: Selenium webdriver: firefox headless inject javascript to modify browser property
it provides a useful pathway.
This is the code:
import os
from selenium import webdriver
options=webdriver.FirefoxOptions()
options.set_headless(True)
driver=webdriver.Firefox(options=options)
# solution found here https://stackoverflow.com/questions/17385779/how-do-i-load-a-javascript-file-into-the-dom-using-selenium
driver.execute_script("var s=window.document.createElement('script'); s.src='javascriptFirefox.js';window.document.head.appendChild(s);")
driver.get('https://auth.citromail.hu/regisztracio/')
Javascript file javascriptFirefox.js
// overwrite the `languages` property to use a custom getter
const setProperty = () => {
Object.defineProperty(navigator, "languages", {
get: function() {
return ["en-US", "en", "es"];
}
});
// Overwrite the `plugins` property to use a custom getter.
Object.defineProperty(navigator, 'plugins', {
get: () => [1, 2, 3, 4, 5],
});
// Pass the Webdriver test
Object.defineProperty(navigator, 'webdriver', {
get: () => false,
});
callback();
};
setProperty();