XmlHttp在Excel中发布VBA不更新网站表单 [英] 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.
URL: 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?
谢谢!
更新:7/26/13上午8:30 PST
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!
URL: https: //oregonup.us/upweb/up/UP_search.asp
但是,当我尝试使用CA未声明的属性网站的状态时,遇到同样的问题。不管我做什么, 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.
URL: 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发布数据视图
URL编码
ResponeText
这篇关于XmlHttp在Excel中发布VBA不更新网站表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!