最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to bypass human verification 'press and hold' using Selenium in Python? - Stack Overflow

programmeradmin0浏览0评论

I am trying to scrape some product reviews using Selenium and Python from this site but it connects another site and shows a popup at any point randomly, where I need to press and hold the button for human verification.

I am using chrome web driver and tried to solve it, to get the path using driver.find_element_by_xpath and many other ways. I also found that the 'Press and Hold' button is inside an iframe and so tried to switch to the iframe by driver.switch_to_frame('//iframe') or driver.switch_to_frame(0) but I failed. I can't find any iframe name or id to take any action.

Is there any way to bypass or take action (pressing and holding the button) whenever it occurs (as a site or popup) and also dismiss other popups during the process using selenium and python? any suggestions would be greatly appreciated!

I am trying to scrape some product reviews using Selenium and Python from this site but it connects another site and shows a popup at any point randomly, where I need to press and hold the button for human verification.

I am using chrome web driver and tried to solve it, to get the path using driver.find_element_by_xpath and many other ways. I also found that the 'Press and Hold' button is inside an iframe and so tried to switch to the iframe by driver.switch_to_frame('//iframe') or driver.switch_to_frame(0) but I failed. I can't find any iframe name or id to take any action.

Is there any way to bypass or take action (pressing and holding the button) whenever it occurs (as a site or popup) and also dismiss other popups during the process using selenium and python? any suggestions would be greatly appreciated!

Share Improve this question edited Aug 3, 2021 at 9:21 Pranta Palit asked Aug 1, 2021 at 17:28 Pranta PalitPranta Palit 7002 gold badges6 silver badges16 bronze badges 7
  • @CodingOtaku No, its different – Pranta Palit Commented Aug 1, 2021 at 17:35
  • As you can see this is not similar to google captcha where you may need to select some car photos or click a checkbox to verify as a human, its totally different, here it requires to press and hold the item/button, where the button is inside an iframe, where the iframe doesn't have any id or name to identify. Its not at all similar as Google captcha, I hope you understand. – Pranta Palit Commented Aug 1, 2021 at 17:41
  • you can switch to the pop up using browser.switch_to_window(browser.window_handles[index_of_window]). If there is no obvious way to get the IFrame then find its xpath to switch to it. "a popup at any point randomly" it's annoying so you'll have to constantly check for its existence. But as I said before, even if you bypass the CAPTCHA, they'll soon change it's behavior to break all crawlers. – Coding Otaku Commented Aug 1, 2021 at 17:46
  • Most of the time, it connects the website for verification where the position of the button is same. But I can't find its xpath or iframe id. Possibly there are some code related to JavaScript with this iframe. At least I need to locate it (as it is shown in the centre) and press and hold it. I can handle other popups, but mainly this one is creating the issue. Randomly means this verification site occurs randomly, we can detect it by matching current url but how to find that button to press it! Idk! – Pranta Palit Commented Aug 1, 2021 at 17:58
  • From what I see, there are 10 Iframes under the <div id="px-captcha">. I believe they are simply selecting one frame randomly and hiding the rest. the one showing the CAPTCH has display:block in the inline styles. does that help? – Coding Otaku Commented Aug 1, 2021 at 18:03
 |  Show 2 more ments

2 Answers 2

Reset to default 2

Jacob's solution from this issue here solves this problem.

import time
from selenium import webdriver as wd
from selenium.webdriver.mon.action_chains import ActionChains

driver = wd.Chrome('./web driver/chromedriver.exe')
target_url = 'https://www.walmart./blocked?url=L2lwL0Nsb3JveC1EaXNpbmZlY3RpbmctV2lwZXMtMjI1LUNvdW50LVZhbHVlLVBhY2stQ3Jpc3AtTGVtb24tYW5kLUZyZXNoLVNjZW50LTMtUGFjay03NS1Db3VudC1FYWNoLzE0ODk4MzY1&uuid=9ed7f800-f288-11eb-ad50-1b3c9c7d7310&vid=9cf07351-f288-11eb-9ab5-ef26d206453b&g=b'
driver.get(target_url)
driver.maximize_window()

element = driver.find_element_by_css_selector('#px-captcha')
action = ActionChains(driver)
action.click_and_hold(element)
action.perform()
time.sleep(10)
action.release(element)
action.perform()
time.sleep(0.2)
action.release(element)

Use Chromedriver Undetected.. Check out the git link for setup. Quite simple to integrate https://github./ultrafunkamsterdam/undetected-chromedriver

import undetected_chromedriver as uc
driver = uc.Chrome()
driver.get('https://www.example.')
发布评论

评论列表(0)

  1. 暂无评论