Python selenium and captcha

后端 未结 1 1979
难免孤独
难免孤独 2021-02-11 05:26

I have a scraping bot which I want to stop whenever it encounters a captcha, so not to annoy the websites. But selenium can\'t find it

driver.find_element_by_xpa         


        
1条回答
  •  醉酒成梦
    2021-02-11 06:01

    AFAIK, captcha usually located inside an iframe, so you can try to switch to iframe before searching for required element:

    frame = driver.find_element_by_xpath('//iframe[contains(@src, "recaptcha")]')
    driver.switch_to.frame(frame)
    driver.find_element_by_xpath("//*[@id='recaptcha-anchor']")
    

    If you need to switch back from iframe:

    driver.switch_to.default_content()
    

    0 讨论(0)
提交回复
热议问题