我经常需要在内华达州搜索无人认领的属性(property),并将结果放入 Excel 电子表格中。我正在尝试自动化该过程,但仅限于使用 Excel 2010 和 VBA。下面是我尝试使用 xmlhttp 提交表单的网站的 URL。
网址:https://nevadatreasurer.gov/UPSearch/
我创建了一个类来自动在其他网站上提交表单,但无论我在帖子数据中输入什么,表单都不会提交。以下是我的提交内容以及提交表单的方法。
调用类(class):
cXML.openWebsite "Post", "https://nevadatreasurer.gov/UPSearch/Index.aspx", _
"ctl04$txtOwner=" & strSearchName
类方法:
Public Sub openWebsite(strOpenMethod As String, strURL As String, _
Optional strPostData As String)
pXmlHttp.Open strOpenMethod, strURL
If strPostData <> "" Then
strPostData = convertSpaceToPlus(strPostData)
pXmlHttp.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
pXmlHttp.send (strPostData)
Else
pXmlHttp.send
End If
'Create DOM html documnet
pHtmlObj.body.innerHTML = pXmlHttp.responseText
End Sub
每次responseText
都是没有更新的主网站,就好像我没有提交postdata一样。我对 IE 自动化相当陌生,但有人可以提供一个不起作用的原因以及一个有效的代码示例吗?
谢谢!
更新:2013 年 7 月 26 日上午 8:30(太平洋标准时间)
无需对我的方法进行任何更改,我就可以通过另一个网站提交表单。状态或无人认领的属性(property)表。效果很完美!
网址:https://oregonup.us/upweb/up/UP_search.asp
但是,当我尝试加州无人认领属性(property)网站的状态时,我遇到了同样的问题。无论我做什么,responseText
始终是原始搜索页面,没有更新。
网址:https://scoweb.sco.ca.gov/UCP/Default.aspx
它仍然不适用于我原来帖子中的 NV 状态。我正在使用正确的帖子数据,为每个网站编码的 URL,看不出有什么区别。任何帮助将不胜感激。
最佳答案
尝试下面的代码
Public Sub openWebsite(strOpenMethod As String, strURL As String, Optional strPostData As String)
Dim pXmlHttp As Object
Set pXmlHttp = CreateObject("MSXML2.XMLHTTP")
pXmlHttp.Open strOpenMethod, strURL, False
pXmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
pXmlHttp.send (strPostData)
Dim pHtmlObj As Object
Set pHtmlObj = CreateObject("htmlfile")
pHtmlObj.body.innerHTML = pXmlHttp.ResponseText
MsgBox pXmlHttp.ResponseText
End Sub
Sub test()
Dim btnSearch As String, strSearchType As String, strSearchName As String, PostData As String
btnSearch = "Search"
strSearchType = "Owner"
strSearchName = "Santosh"
PostData = "ctl04%24txtOwner=" & strSearchName & "&ctl04%24btnSearch=" & btnSearch & "&ctl04%24rblSearchType=" & strSearchType
openWebsite "POST", "https://nevadatreasurer.gov/UPSearch/Index.aspx", PostData
End Sub
使用 Firebug 发布数据 View
URL编码
响应文本
关于vba - Excel VBA 中的 XmlHttp Post 不更新网站表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17818903/