简介: 首先,我想声明,当谈到“HTML”时,我一点都不舒服。我已经对如何完成下面描述的任务进行了详尽的网络搜索。 (例如 Retrieving data from the web using vba、https://www.youtube.com/watch?v=kdD2bb4DU6c、https://www.youtube.com/watch?v=GswfT0Mrr5M)
问题:总而言之想填写一个网站表单(大约 10^3 次),提交查询并得到每个结果。为了测试它并保持简单,我正在测试它的一个值。到目前为止,我设法组合在一起的 VBA 代码是基于其他人所做的。它会打开一个包含所需 URL 的新 IE 窗口,但不会使用“测试”许可证 # (11) 和后缀 (R) 填充所需字段。
Dim HTMLDoc As HTMLDocument
Dim MyBrowser As InternetExplorer
Sub Test()
Dim MyHTML_Element As IHTMLElement
Dim HTMLDoc As HTMLDocument
Dim MyURL As String
On Error GoTo Err_Clear
MyURL = "http://www.dwr.state.co.us/wellpermitsearch/"
''open new explorer
Set MyBrowser = New InternetExplorer
MyBrowser.Silent = True
''navigate to page
MyBrowser.navigate MyURL
MyBrowser.Visible = True
''wait until ready
Do
DoEvents
Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
Set HTMLDoc = MyBrowser.document
''enter permit number and suffix in text box
HTMLDoc.all.txtPermit.Value = "11"
HTMLDoc.all.txtPermitSuf.Value = "R"
'# HTMLDoc.getElementById("txtPermit").attribute.Value = "11"
'# HTMLDoc.getElementById("txtPermitSuf").attribute.Value = "R"
For Each MyHTML_Element In HTMLDoc.getElementsByTagName("input")
'# If MyHTML_Element.ID = "txtPermit" Then MyHTML_Element.Value = "11"
'# If MyHTML_Element.ID = "txtPermitSuf" Then MyHTML_Element.Value = "R"
If MyHTML_Element.Type = "submit" Then MyHTML_Element.Click: Exit For
Next
Err_Clear:
If Err <> 0 Then
Err.Clear
Resume Next
End If
End Sub
我还包含了一些注释代码“'#”,这是 friend 建议我使用的其他可能有效的方法。有谁知道我错过了什么???
提前感谢您的帮助和时间! :)
最佳答案
是您的组织网络阻塞了流量
尝试不同网络上的不同计算机
关于vba - 通过 VBA 填写网络表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29105978/