shahin
Active Member
I've created a macro using xmlhttp requests to get the status of a Parcel ID from a website. This is how to populate the status manually.
1. When you track the site link , you will see an inputbox right next to parcel id. Use this id 03008088 and press the search button. You should see a new page exactly like I've shown in the image two.
2. Now click on the view bill button which should lead you to the result page which you can see in image three.
3. I'm after this text `Parcel is in tax sale`.
This is the site link: https://taxpayments.carolinemd.org/MSS/citizens/RealEstate/Default.aspx?mode=new
It is necessary to encode the strings "mystring" and "mynewstring" which are supposed to be sent with post requests. When it comes to encode string, I usually go for "WorksheetFunction.EncodeURL()" but in this very case I could notice that the script encounters this error (Run-time error 1004. Unable to get the encodeurl property of the worksheetfunction class.) when I use "WorksheetFunction.EncodeURL()" within "mynewstring" so, I used "EncodeURL()" function instead of "WorksheetFunction.EncodeURL()" to encode the strings. I'm using win 32 and the following macro automates the aforesaid steps flawlessly.
However, I could get a complaint that it doesn't work in 64 bit. Could you help me figure out what happens when the following macro is made to run in 64 bit windows as it works flawlessly in 32 bit?
Once again If you are using 32 bit windows, you see `Parcel is in tax sale` when you execute the macro. However, you will encounter some error when you are on 64 bit windows and that is what I'm trying to seek a solution for.
1. When you track the site link , you will see an inputbox right next to parcel id. Use this id 03008088 and press the search button. You should see a new page exactly like I've shown in the image two.
2. Now click on the view bill button which should lead you to the result page which you can see in image three.
3. I'm after this text `Parcel is in tax sale`.
This is the site link: https://taxpayments.carolinemd.org/MSS/citizens/RealEstate/Default.aspx?mode=new
It is necessary to encode the strings "mystring" and "mynewstring" which are supposed to be sent with post requests. When it comes to encode string, I usually go for "WorksheetFunction.EncodeURL()" but in this very case I could notice that the script encounters this error (Run-time error 1004. Unable to get the encodeurl property of the worksheetfunction class.) when I use "WorksheetFunction.EncodeURL()" within "mynewstring" so, I used "EncodeURL()" function instead of "WorksheetFunction.EncodeURL()" to encode the strings. I'm using win 32 and the following macro automates the aforesaid steps flawlessly.
However, I could get a complaint that it doesn't work in 64 bit. Could you help me figure out what happens when the following macro is made to run in 64 bit windows as it works flawlessly in 32 bit?
Code:
Public Function EncodeURL(url As Variant) As String
Dim buffer As String, i As Long, c As Long, n As Long
buffer = String$(Len(url) * 12, "%")
For i = 1 To Len(url)
c = AscW(Mid$(url, i, 1)) And 65535
Select Case c
Case 48 To 57, 65 To 90, 97 To 122, 45, 46, 95 ' Unescaped 0-9A-Za-z-._ '
n = n + 1
Mid$(buffer, n) = ChrW(c)
Case Is <= 127 ' Escaped UTF-8 1 bytes U+0000 to U+007F '
n = n + 3
Mid$(buffer, n - 1) = Right$(Hex$(256 + c), 2)
Case Is <= 2047 ' Escaped UTF-8 2 bytes U+0080 to U+07FF '
n = n + 6
Mid$(buffer, n - 4) = Hex$(192 + (c \ 64))
Mid$(buffer, n - 1) = Hex$(128 + (c Mod 64))
Case 55296 To 57343 ' Escaped UTF-8 4 bytes U+010000 to U+10FFFF '
i = i + 1
c = 65536 + (c Mod 1024) * 1024 + (AscW(Mid$(url, i, 1)) And 1023)
n = n + 12
Mid$(buffer, n - 10) = Hex$(240 + (c \ 262144))
Mid$(buffer, n - 7) = Hex$(128 + ((c \ 4096) Mod 64))
Mid$(buffer, n - 4) = Hex$(128 + ((c \ 64) Mod 64))
Mid$(buffer, n - 1) = Hex$(128 + (c Mod 64))
Case Else ' Escaped UTF-8 3 bytes U+0800 to U+FFFF '
n = n + 9
Mid$(buffer, n - 7) = Hex$(224 + (c \ 4096))
Mid$(buffer, n - 4) = Hex$(128 + ((c \ 64) Mod 64))
Mid$(buffer, n - 1) = Hex$(128 + (c Mod 64))
End Select
Next
EncodeURL = Left$(buffer, n)
End Function
Sub GetInformation()
Const url = "https://taxpayments.carolinemd.org/MSS/citizens/RealEstate/Default.aspx?mode=new"
Const innerUrl = "https://taxpayments.carolinemd.org/MSS/citizens/RealEstate/ParcelBrowse.aspx"
Dim mystring As Variant, i&, n&, elem$, Htmldoc As New HTMLDocument, searchKey$, kstr As Variant
Dim Row&, MyDict As Object, aMyDict As Object, DictKey As Variant, oelem As Object, mynewstring As Variant
Dim Http As Object: Set Http = CreateObject("MSXML2.XMLHTTP")
Set MyDict = CreateObject("Scripting.Dictionary")
Set aMyDict = CreateObject("Scripting.Dictionary")
With Http
.Open "GET", url, True
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36"
.send
While .readyState < 4: DoEvents: Wend
Htmldoc.body.innerHTML = .responseText
End With
With Htmldoc.querySelectorAll("input[name]")
For n = 0 To .Length - 1
On Error Resume Next
MyDict.Add .Item(n).getAttribute("name"), .Item(n).getAttribute("value")
On Error GoTo 0
Next n
End With
MyDict("ctl00$ctl00$PrimaryPlaceHolder$ContentPlaceHolderMain$Control$ParcelIdSearchFieldLayout$ctl01$ParcelIDTextBox") = "03008088"
kstr = "ctl00$ctl00$PrimaryPlaceHolder$ContentPlaceHolderMain$Control$FormLayoutItem7$ctl01$resetButton"
If MyDict.exists(kstr) Then
MyDict.Remove kstr
End If
For Each DictKey In MyDict
mystring = IIf(Len(DictKey) = 0, EncodeURL(DictKey) & "=" & EncodeURL(MyDict(DictKey)), _
mystring & "&" & EncodeURL(DictKey) & "=" & EncodeURL(MyDict(DictKey)))
Next DictKey
With Http
.Open "POST", url, True
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36"
.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
.send mystring
While .readyState < 4: DoEvents: Wend
Htmldoc.body.innerHTML = .responseText
End With
elem = Htmldoc.querySelector("a.functionlink[id][href*='__doPostBack']").getAttribute("href")
elem = Split(Split(elem, "__doPostBack('")(1), "',")(0)
With Htmldoc.querySelectorAll("input[name]")
For n = 0 To .Length - 1
On Error Resume Next
aMyDict.Add .Item(n).getAttribute("name"), .Item(n).getAttribute("value")
On Error GoTo 0
Next n
End With
aMyDict("__EVENTTARGET") = elem
For Each DictKey In aMyDict
mynewstring = IIf(Len(DictKey) = 0, EncodeURL(DictKey) & "=" & EncodeURL(aMyDict(DictKey)), _
mynewstring & "&" & EncodeURL(DictKey) & "=" & EncodeURL(aMyDict(DictKey)))
Next DictKey
With Http
.Open "POST", innerUrl, True
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36"
.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
.send mynewstring
While .readyState < 4: DoEvents: Wend
Htmldoc.body.innerHTML = .responseText
End With
Set oelem = Htmldoc.querySelector("p.taxSaleAlertStyle")
MsgBox oelem.innerText
End Sub
Once again If you are using 32 bit windows, you see `Parcel is in tax sale` when you execute the macro. However, you will encounter some error when you are on 64 bit windows and that is what I'm trying to seek a solution for.