我是一名 VBA 新手,也是 Stack Overflow 的新手,尽管我已经阅读这里的帖子有一段时间了。我已经搜索了很多编码问题的答案,但似乎找不到答案。我正在尝试登录网站,导航到页面,然后从该页面抓取数据。我已经开始构建我从互联网上找到的内容一起解析的代码。在使用“获取元素”查找 ID 后,我似乎无法让 IE 将我的凭据放入相应的用户和密码框中。我最终得到的是运行时错误 424 - 需要对象。预先感谢您的任何帮助。
'Open IE, navigate to the desired page and loop until fully loaded
Set IE = CreateObject("InternetExplorer.Application")
site = "https://www.ivolatility.com/login.j"
With IE
.Visible = True
.navigate site
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
End With
'Input the userid and password
IE.Document.getElementById("username").Value = "xxxxxx"
IE.Document.getElementById("password").Value = "xxxxxx"
'Click the "Search" button
IE.Document.getElementById("login_go").Click
Do Until Not IE.Busy And IE.readyState = 4
DoEvents
Loop
您正在尝试使用 HTML 输入元素的name as its id尽管有时您会看到,但这两者不一定相同。
<input type="text" id="username" name="username" value="" size="10" class="s2" maxlength="63 ">
但他这里的情况并非如此。您需要按元素的名称而不是 ID 来处理元素。
dim n as long 'this belongs at hte top witrh the other Dims
'Input the userid and password
For n = 0 To ie.document.getelementsbytagname("input").Length - 1
With ie.document.getelementsbytagname("input")(n)
Select Case LCase(.Name)
Case "username"
.Value = "xxxxxx"
Case "password"
.Value = "zzzzzz"
Case "login_go"
.Click
n = 99999
Case Else
'ignore
End Select
End With
Next n
Do While ie.Busy Or ie.readyState <> 4: DoEvents: Loop
在这种情况下,单击有效,因为提交发生在名为的输入元素之后username and password.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)