Im building a webscraper for a client right now, but its getting caught by the sites anti-scraping system "Bot Defender." Ive found that it only gets caught when I let the program enter the username or pass, but doesnt get caught if I enter it manually. any ideas why? can the site tell the difference between seleniums webdriver.sendkeys()
method and keyboard strokes?
My code is below:
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager
import undetected_chromedriver.v2 as uc
from random import randint, choice
email_address = '' #insert your email login
password = '' #insert your password
def random_sleep(start=3, end=5):
s=randint(0,100)*((end-start)/100)+start
sleep(s)
def start_uc(headless=False):
options = webdriver.ChromeOptions()
options.headless= headless
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_argument('--no-first-run --no-service-autorun --password-store=basic')
driver = uc.Chrome(options=options)
return driver
def start():
driver = start_uc()
while True:
try:
driver.get("https://sportsbook.fanduel.com/")
WebDriverWait(driver, 30).until(EC.title_is("FanDuel Sportsbook - Legal Online Sports Betting and Sportsbook"))
break
except:
pass
print('Title: ' + driver.title)
random_sleep()
# driver.find_element(By.XPATH, '//*[@id="root"]/div/div[1]/div/header/div[2]/div[1]/a[1]/svg/g').click()
driver.find_element(By.XPATH,'//a[@href="/login"]').click()
random_sleep()
driver.find_element(By.XPATH,'//a[@data-test-id="state-selection--CO"]').click()
random_sleep()
email = driver.find_element(By.XPATH,'//input[@type="email"]')
email.click()
for let in email_address:
random_sleep(0.2,1)
email.send_keys(let)
random_sleep()
pw = driver.find_element(By.XPATH,'//input[@type="password"]')
pw.click()
for let in password:
random_sleep(0.2,1)
pw.sendkeys(let)
random_sleep()
pw.send_keys(Keys.RETURN)
random_sleep(20,30)
driver.quit()
if __name__ == "__main__":
start()