【问题标题】:How to solve Walmart Robot or Human challenge?如何解决沃尔玛机器人或人类挑战?
【发布时间】:2022-01-13 01:06:19
【问题描述】:

我已经编译了一个代码,可以使用 selenium python 在https://www.walmart.com/ 上创建一个帐户。代码打开沃尔玛网站,转到创建帐户选项卡,填写所需的详细信息,然后单击创建帐户按钮。然而,问题在于沃尔玛的人工验证挑战,它在任何阶段随机出现。以下是打开 URL 或单击创建帐户按钮后出现的人工验证挑战的快照:

我在 stackoverflow 上找到了绕过这个挑战的代码(如下所示),但它对我不起作用。

element = driver.find_element(By.CSS_SELECTOR, '#px-captcha')
action = ActionChains(driver)
action.click_and_hold(element)
action.perform()
time.sleep(100)
action.release(element)
action.perform()
time.sleep(0.2)
action.release(element)

作为参考,我的python代码如下:

import time
import requests
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.action_chains import ActionChains

url = "https://www.walmart.com/"

first_name = "chuza"
last_name = "789"
email_id = "chuza789@gmail.com"
password = "Eureka1@"

options = Options()

s=Service('C:/Users/Samiullah/.wdm/drivers/chromedriver/win32/96.0.4664.45/chromedriver.exe')
driver = webdriver.Chrome(service=s, options=options)
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {
    "source":
        "const newProto = navigator.__proto__;"
        "delete newProto.webdriver;"
        "navigator.__proto__ = newProto;"
})
wait = WebDriverWait(driver, 20)
actions = ActionChains(driver)
driver.get(url)

sign_in_btn = wait.until(EC.visibility_of_element_located((By.XPATH, "//div[text()='Sign In']")))
actions.move_to_element(sign_in_btn).perform()
time.sleep(0.5)
wait.until(EC.visibility_of_element_located((By.XPATH, '//button[normalize-space()="Create an account"]'))).click()

f_name = driver.find_element(By.ID, 'first-name-su')
l_name = driver.find_element(By.ID, 'last-name-su')
email = driver.find_element(By.ID, 'email-su')  
pswd = driver.find_element(By.ID, 'password-su')
f_name.send_keys(first_name)
driver.implicitly_wait(2)
l_name.send_keys(last_name)
driver.implicitly_wait(2.5)
email.send_keys(email_id)
driver.implicitly_wait(3)
pswd.send_keys(password)
driver.implicitly_wait(2.8)
###
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[data-automation-id='signup-submit-btn']"))).click()

谁能指导我如何解决沃尔玛的机器人或人类?挑战以及如何将其与我现有的代码集成?提前致谢。

【问题讨论】:

标签: python-3.x selenium selenium-webdriver web-scraping captcha


【解决方案1】:

解决此问题的最简单方法是检查此元素是否存在。
如果该元素出现 - 执行页面重新加载,直到该元素不再存在。
像这样的:

human_dialog = driver.find_elements(By.XPATH, "//div[@aria-labelledby='ld_modalTitle_0']")
while human_dialog:
    driver.refresh()
    time.sleep(1)
    human_dialog = driver.find_elements(By.XPATH, "//div[@aria-labelledby='ld_modalTitle_0']")

【讨论】:

    猜你喜欢
    • 2011-03-28
    • 2019-02-07
    • 1970-01-01
    • 2018-01-29
    • 1970-01-01
    • 2020-10-11
    • 2014-09-19
    • 1970-01-01
    • 2014-08-12
    相关资源
    最近更新 更多