gpt4 book ai didi

excel - 填写网页中的两个输入字段

转载 作者:行者123 更新时间:2023-12-04 22:30:53 29 4
gpt4 key购买 nike

我在 VBA 中结合 IE 编写了一个脚本来填充两个输入字段以登录网页。

当我尝试执行我的脚本时,它会抛出 Access is denied 由于 iframe 导致的错误输入字段在其中。如何用我的凭据填写两个输入字段?

This is the site link

到目前为止,这是我的尝试:

Sub LogIn()
Const Url = "replace with above link"
Dim IE As New InternetExplorer, HTML As HTMLDocument
Dim frm As Object, post As Object

With IE
.Visible = True
.navigate Url
While .Busy Or .readyState < 4: DoEvents: Wend
Set HTML = .document
End With

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

Set frm = HTML.querySelector("iframe[name='disneyid-iframe']").contentWindow.document
Set post = frm.querySelector("input[placeholder='Username or Email Address']")
post.Value = "somename@gmailmail.com"
End Sub

您可以尝试使用任何输入详细信息。我只需要知道如何填写这两个框。

连接到 iframe 的 HTML 元素内容:
<iframe id="disneyid-secure-responder" name="disneyid-secure-responder" src="https://www.espn.com/disneyid/responder/index.html?clientId=ESPN-ONESITE.WEB-PROD&amp;scheme=http&amp;postMessageOrigin=http%3A%2F%2Ffantasy.espn.com%2Fbasketball%2Fteam%3FleagueId%3D24874190%26teamId%3D1%26statSplit%3DcurrSeason&amp;cookieDomain=espn.com&amp;config=PROD&amp;logLevel=INFO&amp;topHost=fantasy.espn.com&amp;ageBand=ADULT&amp;countryCode=CA&amp;langPref=en-US&amp;cssOverride=https%3A%2F%2Fsecure.espncdn.com%2Fcombiner%2Fc%3Fcss%3Ddisneyid%2Fcore.css%2Cdisneyid%2Ffantasy.css&amp;responderPage=https%3A%2F%2Fwww.espn.com%2Fdisneyid%2Fresponder%2Findex.html&amp;buildId=165f40c7564" style="display: none;"></iframe>

最佳答案

如另一个答案中所述,iframe src位于不同的域中并且 same domain policy在这种情况下,有效地排除了 > 版本 8 的 IE。虽然弄乱安全设置以试图绕过这是一个坏主意,请参阅 this阅读。

使用 selenium basic 这很容易对于使用 Chrome 的 VBA。您还需要循环,直到可以输入登录详细信息。我添加了超时以防止无限循环。

安装 selenium 后,您需要转到 VBE > Tools > References 并添加对 Selenium 类型库的引用。

Option Explicit    
Public Sub Login()
Dim d As WebDriver, ele As WebElement, t As Date
Const MAX_WAIT_SEC As Long = 5
Const url = "http://fantasy.espn.com/basketball/team?leagueId=24874190&teamId=1&statSplit=currSeason"
Set d = New ChromeDriver

With d
.Start "Chrome"
.get url
t = Timer
Do
DoEvents
On Error Resume Next
.SwitchToFrame .FindElementById("disneyid-iframe")
Set ele = .FindElementByCss("[type=email]")
On Error GoTo 0
If Timer - t > MAX_WAIT_SEC Then Exit Do
Loop While Not ele.IsDisplayed

If ele Is Nothing Then Exit Sub

ele.SendKeys "Bob@Builder.com"
.FindElementByCss("[type=password]").SendKeys "password"
.FindElementByCss("[type=submit]").Click

Stop '<== Delete me later
'Other code
.Quit
End With
End Sub

关于excel - 填写网页中的两个输入字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52917166/

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