问题
I'm trying to make a bot for https://www.phonehouse.nl/verlengchecker . But when I use Chrome it gets detected. When I use Firefox it only opens the page and doesn't do anything. I tried it on Arch linux and Windows result is the same.
from selenium import webdriver
from time import sleep
capabilities = {
'browserName': 'chrome',
'chromeOptions': {
'useAutomationExtension': False,
'forceDevToolsScreenshot': True,
'args': ['--start-maximized', '--disable-infobars']
}
}
driver = webdriver.Chrome(capabilities=capabilities)
def control(provider, number, day, month, year, post, email, street):
driver.get("https://www.phonehouse.nl/verlengchecker")
sleep(1)
driver.find_element_by_xpath("//span[@id='businessSelectBoxIt']").send_keys(provider) #provider
driver.find_element_by_xpath("//input[@name='msisdn']").send_keys(number) #number
回答1:
Your analysis was in the right direction. Selenium driven ChromeDriver initiated google-chrome Browsing Context can easily get detected by the recaptcha.
Deep Dive
If you access the DOM Tree you will find the existance of the recaptcha.
Conclusion
Recaptcha can easily detect WebDriver initiated Browsing Context.
You can find a detailed discussion in How does recaptcha 3 know I'm using selenium/chromedriver?
However there are some generic ways to avoid detection and you can find a detailed discussion in How to bypass Google captcha with Selenium and Python?
Outro
You can find a relevant detailed discussion in:
- Can a website detect when you are using selenium with chromedriver?
回答2:
Well, the "provider" space isn't an input so you can't use send_keys
,
But you can use this for the number:
from selenium import webdriver
from time import sleep
driver = webdriver.Firefox()
def control(number):
driver.get("https://www.phonehouse.nl/verlengchecker")
sleep(1)
driver.find_element_by_xpath('//*[@id="msisdn"]').send_keys(number)
control("000")
来源:https://stackoverflow.com/questions/62973702/selenium-chrome-gets-detected