I was trying to make a selenium bot that executes through firefox geckodriver but when I use AntiBot detection website like (https://bot.sannysoft.com/) it shows WebDriver as present.
Antibot shows WebDriver as present
I tried the same test on ChromeDriver it was solved with 2 lines of additions.
self.options.add_argument('--disable-blink-features=AutomationControlled')
self.options.add_experimental_option('excludeSwitches', ['enable-logging'])
and I'm using the selenium library with version:
selenium==4.9.0
Heres my code for what I tried but did not work:
import pickle
from selenium import webdriver
class ANTIBOT(webdriver.Firefox):
def __init__(self, teardown=False):
self.teardown = teardown
self.firefox_driver_path = r'C:\SeleniumDriver\geckodriver.exe'
self.firefox_binary_path = r'C:\Program Files\Mozilla Firefox\firefox.exe'
self.firefox_profile_path = r'C:\Users\user\AppData\Roaming\Mozilla\Firefox\Profiles\p25v0mcm.default-release'
self.options = webdriver.FirefoxOptions()
self.options.add_argument('--disable-blink-features=AutomationControlled')
self.options.set_preference('profile', self.firefox_profile_path)
self.options.set_preference('network.proxy.type', 1)
self.options.set_preference('network.proxy.socks', '127.0.0.1')
self.options.set_preference('network.proxy.socks_port', 9050)
self.options.set_preference("network.proxy.socks_remote_dns", False)
self.options.set_preference('dom.webdriver', False)
self.options.set_preference('enable-automation', False)
self.options.set_preference('dom.webdriver.enabled', False)
self.options.set_preference('useAutomationExtension', False)
self.options.set_preference('devtools.jsonview.enabled', False)
self.options.set_preference('marionette.enabled', False)
self.options.set_preference('fission.bfcacheInParent', False)
self.options.set_preference('fission.webContentIsolationStrategy', 0)
self.options.set_capability('marionette', False)
self.options.binary_location = self.firefox_binary_path
self._service = Service(self.firefox_driver_path)
super(ANTIBOT, self).__init__(
options=self.options,
service=self._service,
)
self.execute_script('Object.defineProperty(navigator, "webdriver", {get: () => undefined})')
self.implicitly_wait(60)
# self.maximize_window()
def __exit__(self, exc_type, exc_val, exc_tb):
if self.teardown:
self.quit()
def save_cookies(self):
pickle_filename = 'cookies.pkl'
pickle.dump(self.get_cookies(), open(pickle_filename, 'wb'))
def load_cookies(self):
cookies = pickle.load(open('cookies.pkl', 'rb'))
if len(cookies) > 0:
for cookie in cookies:
self.add_cookie(cookie)
self.refresh()
def load_bot_detector(self):
self.get('https://bot.sannysoft.com/')
self.implicitly_wait(30)
if __name__ == '__main__':
with ANTIBOT(teardown=False) as antibot:
antibot.save_cookies()
antibot.load_cookies()
antibot.load_bot_detector()