gpt4 book ai didi

excel - Excel VBA、Selenium 和 Chromedriver 的网站登录问题

转载 作者:行者123 更新时间:2023-12-04 20:02:41 29 4
gpt4 key购买 nike

我在 Excel 2016 中使用 VBA 宏以及 Chrome 和 Selenium WebDriver 登录到许多不同的网站,但我无法使用以下代码以编程方式登录 AARP 网站。

' Open the "AARP" web page
WDriver.Start "chrome"
WDriver.Window.Maximize
WDriver.Get "https://www.medicare.uhc.com/AARP"

Application.Wait (Now + TimeValue("0:00:05"))

' Find the "Sign In" button and click it
Set Results = WDriver.FindElementsByTag("button")
For Each itm In Results
If InStr(1, itm.Text, "Sign In", vbTextCompare) > 0 Then
itm.Click
Exit For
Else
End If
Next itm

' Wait until the page is fully loaded
Application.Wait (Now + TimeValue("0:00:10"))

' Enter Email address and PW and then click the Login button
WDriver.FindElementById("EMAIL").SendKeys ("") ' focus
WDriver.FindElementById("EMAIL").SendKeys ("abcd")
Application.Wait (Now + TimeValue("0:00:02"))

WDriver.FindElementById("PASSWORD").SendKeys ("") ' focus
WDriver.FindElementById("PASSWORD").SendKeys ("1234")
Application.Wait (Now + TimeValue("0:00:02"))

WDriver.FindElementById("submitBtn").Click

' Do stuff
我可以看到 EMAIL 地址和密码是正确的并插入到正确的文本框中,但是当单击提交按钮时,一个小轮子旋转了几分之一秒,但未更改的网页仍然显示我的电子邮件和密码。
如果我现在手动输入正确的电子邮件和密码,小轮子会再次旋转一秒钟,但同样没有任何 react ——没有错误消息,什么也没有。该页面无法再进行交互。如果我想尝试其他东西,我需要关闭网页并从头开始使用新的 Chrome 实例。
如果我从头开始并手动插入我的电子邮件和密码,网站会很好地登录我。如果我手动输入了错误的电子邮件并且 pw 我收到以下消息,

"Error: The username and password combination entered does not matchour records."


什么代码会成功插入用户名和密码,以便网页可以处理? 当您收到上面显示的错误消息 时,您将知道您的代码有效。
EMAIL输入框的源码是
<input id="EMAIL" class="form-control ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required" type="text" name="EMAIL" ng-model="sm.userInput" placeholder="" required="required" ng-blur="isValidUserNameEmail()" aria-invalid="true" data-nlok-ref-guid="345cd641-a989-4cee-a891-7e7cb5e43669">
PASSWORD 输入框的源代码非常相似。

最佳答案

问题出在网站上,如今一些网站出于各种原因阻止了自动化。所以,你必须欺骗他们认为你不是。下面的链接很好地解释了如何解决这个问题,我之前用 python 做过一些,但是随着 vba selenium 已经过时,我会选择网站上的第二个选择:“混淆浏览器驱动程序 EXE 的 JavaScript ”。
本质上,您在文本编辑器 (C:\Users$User$\AppData\Local\SeleniumBasic) 中编辑 ChromeDriver。然后搜索以下文本:“$cdc_asdjflasutopfhvcZLmcfl_”。找到它后,将其替换为“$btlhsaxJbTXmBATUDvTRhvcZLm_”之类的内容或任何相同长度的内容。我在执行此操作之前对其进行了测试,并且在我能够登录后遇到了与您相同的错误。
https://piprogramming.org/articles/How-to-make-Selenium-undetectable-and-stealth--7-Ways-to-hide-your-Bot-Automation-from-Detection-0000000017.html

关于excel - Excel VBA、Selenium 和 Chromedriver 的网站登录问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67167164/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com