如何在 Python 中使用 Selenium 绕过人工验证 'press and hold'?
How to bypass human verification 'press and hold' using Selenium in Python?
我正在尝试使用 Selenium 和 Python 从这个 site but it connects another site 中抓取一些产品评论,并在任何时候随机显示一个弹出窗口,我需要按住按钮进行人工验证。
我正在使用 chrome 网络驱动程序并尝试解决它,使用 driver.find_element_by_xpath
和许多其他方法来获取路径。我还发现 'Press and Hold' 按钮位于 iframe 内,因此尝试通过 driver.switch_to_frame('//iframe')
或 driver.switch_to_frame(0)
切换到 iframe 但我失败了。我找不到任何 iframe 名称或 ID 来执行任何操作。
是否有任何方法可以绕过或采取行动(按住按钮)每当它发生时(作为站点或弹出窗口)并在使用 selenium 和 [=26 的过程中关闭其他弹出窗口=]?
任何建议将不胜感激!
Jacob 在这个问题上的解决方案 解决了这个问题。
import time
from selenium import webdriver as wd
from selenium.webdriver.common.action_chains import ActionChains
driver = wd.Chrome('./web driver/chromedriver.exe')
target_url = 'https://www.walmart.com/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)
我正在尝试使用 Selenium 和 Python 从这个 site but it connects another site 中抓取一些产品评论,并在任何时候随机显示一个弹出窗口,我需要按住按钮进行人工验证。
我正在使用 chrome 网络驱动程序并尝试解决它,使用 driver.find_element_by_xpath
和许多其他方法来获取路径。我还发现 'Press and Hold' 按钮位于 iframe 内,因此尝试通过 driver.switch_to_frame('//iframe')
或 driver.switch_to_frame(0)
切换到 iframe 但我失败了。我找不到任何 iframe 名称或 ID 来执行任何操作。
是否有任何方法可以绕过或采取行动(按住按钮)每当它发生时(作为站点或弹出窗口)并在使用 selenium 和 [=26 的过程中关闭其他弹出窗口=]? 任何建议将不胜感激!
Jacob 在这个问题上的解决方案
import time
from selenium import webdriver as wd
from selenium.webdriver.common.action_chains import ActionChains
driver = wd.Chrome('./web driver/chromedriver.exe')
target_url = 'https://www.walmart.com/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)