简体   繁体   English

无法在 Chrome WebDriver 中使用 Selenium 登录 Target.com

[英]Unable to log in to Target.com using Selenium in Chrome WebDriver

I am trying to log on to Target's website using Selenium in Python with the Chrome WebDriver..我正在尝试使用 Python 中的 Selenium 和 Chrome WebDriver 登录 Target 的网站。

When I am prompted to log in, I use the following code:当系统提示我登录时,我使用以下代码:

self.browser.find_element_by_name("password").send_keys(pw)
self.browser.find_element_by_id("login").submit()

After the field is submitted, I am presented with this error in the DOM:提交字段后,我在 DOM 中看到此错误:

DOM Error Alert DOM 错误警报

..and this in the console: ..这在控制台中:

401 Error 401错误

Note:笔记:

I have tried logging in with Selenium on Instagram, and it works.. So I know it has something to do with the structure of Target's website.我试过在 Instagram 上使用 Selenium 登录,并且有效。所以我知道这与 Target 网站的结构有关。 Has anyone run into this issue before?有没有人遇到过这个问题?

Thanks!谢谢!

So I originally tried solving this issue using Chrome, but could not figure out why the page would not precede after entering the login data.所以我最初尝试使用 Chrome 解决这个问题,但无法弄清楚为什么在输入登录数据后页面不会出现。 I thought maybe the page was protected by some bot software, but could not find any proof.我想也许该页面受到某些机器人软件的保护,但找不到任何证据。

I decided to try Safari on my MAC, and actually had success.我决定在我的 MAC 上尝试 Safari,实际上成功了。 See the below code:请参阅以下代码:

import time
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys

driver = webdriver.Safari(executable_path='/usr/bin/safaridriver')
driver.get('https://www.target.com/')
action = ActionChains(driver)
driver.find_element(By.XPATH, '//*[@id="account"]').click()
WebDriverWait(driver, 30).until(ec.presence_of_element_located((By.XPATH, '//*[@id="accountNav-signIn"]')))
action.send_keys(Keys.ENTER)
action.perform()
WebDriverWait(driver, 10).until(ec.presence_of_element_located((By.XPATH, '//h2[@class="sc-hMqMXs sc-esjQYD eXTUDl"]')))
driver.find_element(By.ID, 'username').click()
driver.find_element(By.ID, 'username').send_keys('foo')
time.sleep(5)
driver.find_element(By.ID, 'password').click()
driver.find_element(By.ID, 'password').send_keys('bar')
time.sleep(5)
driver.find_element(By.XPATH, "//button[@id=\'login\']").send_keys(Keys.ENTER)
time.sleep(10)
driver.quit()

You will notice some time.sleeps which I am using to slow the program down (you can take these out).你会注意到一些 time.sleeps,我用它来减慢程序速度(你可以把它们去掉)。

I also tried on FireFox and Edge, but had the same problems as Chrome.我也尝试了 FireFox 和 Edge,但遇到了与 Chrome 相同的问题。

Conclusion, it seems there could be some sort of bot protection which is blocking you from using Chrome (also Edge and FireFox).结论,似乎有某种机器人保护阻止您使用 Chrome(还有 Edge 和 FireFox)。 Given these webdrivers are being detected as automated.鉴于这些网络驱动程序被检测为自动化。 Safari (I believe) does not get detected as such. Safari(我相信)没有被检测到。

I would also suggest reading through the below post, it may offer more insight.我还建议阅读下面的帖子,它可能会提供更多见解。 Website navigates to no-access page using ChromeDriver and Chrome through Selenium probably Bot Protected 网站通过 Selenium 可能使用 ChromeDriver 和 Chrome 导航到无访问页面可能受 Bot Protected

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 Selenium 登录 Target.com - Can't login to Target.com with Selenium 由于 xpath 中的一些错误,无法从 target.com 中抓取评论 - Unable to scrape reviews from target.com due to some error in xpath 如何在 Firefox 或 Chrome 中使用 Selenium webdriver 更改屏幕截图的目标目录 - How to change the target directory for a screenshot using Selenium webdriver in Firefox or Chrome 无法在 python selenium 中使用 selenium chrome webdriver 定位元素 - Unable to locate element using selenium chrome webdriver in python selenium Selenium webdriver chrome,无法使用 CSS 选择器或 XPath 定位按钮 - Selenium webdriver chrome, unable to locate button using CSS selector or XPath 使用谷歌浏览器的硒网络驱动程序 - selenium webdriver using Google Chrome 使用带有 chrome 的 Selenium Webdriver 时出错 - Errror with using Selenium Webdriver with chrome 无法使用 Selenium for Python 打开 Chrome WebDriver - Unable to Open Chrome WebDriver with Selenium for Python [Python] [Selenium]无法在Chrome中使用网络驱动程序 - [Python][Selenium]Unable to use webdriver with Chrome 无法使用 selenium webdriver python 下载目标用户的 Instagram 帖子中的图像 - Unable to download images in Instagram posts of target user using selenium webdriver python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM