通过VBA填写Web表单

简介:我首先想说的是,当谈到“HTML”时,我感到不舒服。 我已经完成了如何完成下面描述的任务的网页search。 (例如使用vba从 https上 获取数据 , https : //www.youtube.com/watch?v= kdD2bb4DU6c , https : //www.youtube.com/watch?v= GswfT0Mrr5M )

问题:总之想填写一个网站表格(约10 ^ 3次),提交查询并得到每个结果。 为了testing它,并保持简单,我正在testing它的一个值。 到目前为止,我所devise的VBA代码是基于别人所做的。 它打开一个新的IE浏览器窗口与所需的URL,但它没有填写“testing”许可证#(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 

我还包括一些评论代码“##”,这是朋友build议我可以使用的其他方式。 有没有人有任何想法我错过了什么?

提前感谢您的帮助和时间! 🙂

这是您的组织networking阻止stream量

在另一个networking上尝试另一台计算机