Excel VBA中的XmlHttp Post不更新网站表单 [英] XmlHttp Post in Excel VBA not updating website form
问题描述
我经常需要在 NV 的状态中搜索无人认领的财产,并将结果放入 Excel 电子表格中.我正在尝试自动化该过程,但我仅限于使用 Excel 2010 和 VBA.下面是我尝试使用 xmlhttp 提交表单的网站的 URL.
I routinely have to search the state of NV for unclaimed property and put the results in an Excel spreadsheet. I am trying to automate the process but I'm limited to using Excel 2010 and VBA. Below is the URL to the site I'm trying to submit a form using xmlhttp.
网址:https://nevadatreasurer.gov/UPSearch/
我创建了一个类来自动在其他网站上提交表单,但无论我在 postdata 中输入什么,表单都永远不会提交.以下是我的提交,以及提交表单的方法.
I created a class to automate submitting forms on other websites but no matter what I enter in the postdata the form is never submitted. Below is my submission, and method to submit the form.
上课:
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 自动化相当陌生,但有人可以提供一个不起作用的原因以及一个有效的代码示例吗?
Each time the responseText
is the main website with no updates, as if I submitted no postdata. I'm fairly new to IE automation but can someone provide a reason why this isn't working and a code example that works?
谢谢!
更新:太平洋标准时间 2013 年 7 月 26 日上午 8:30
Update: 7/26/13 8:30am PST
无需对我的方法进行任何更改,我就可以通过另一个网站提交表单.OR 无人认领财产表格的状态.效果很好!
Without any changes to my method I was able to submit forms through another website. The state of OR unclaimed property form. It worked perfect!
网址:https://oregonup.us/upweb/up/UP_search.asp
但是,当我尝试加利福尼亚州无人认领的财产网站时,我遇到了同样的问题.无论我做什么,responseText
始终是没有更新的原始搜索页面.
However I ran into the same problem when I tried the state of CA unclaimed property website. No matter what I do, the responseText
is always the original search page with no update.
网址:https://scoweb.sco.ca.gov/UCP/Default.aspx
它仍然不适用于我原来帖子中的 NV 状态.我正在使用正确的帖子数据,为每个网站编码的 URL,看不出有什么区别.任何帮助将不胜感激.
It still does not work with the state of NV on my original post. I am using the proper post data, URL encoded for each website and can see no difference. Any help would be appreciated.
推荐答案
试试下面的代码
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 发布数据视图
网址编码
响应文本
这篇关于Excel VBA中的XmlHttp Post不更新网站表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!