excel - Unable to grab a portion of text from a website using post http requests
问题描述
I'm trying to parse the text within yellow colored area from a website which is visible when you fill in the inputbox next to parcel id and hit the search button. Here is an example parcel id 01-01-350000
for your test.
I've created a macro using xmlhttp requests to scrape the very content. It seems I've done everything in the right way but for some reason the macro is not working. It is still in the landing page even after making a post requests.
I've tried with:
Sub GetStatus()
Const Url$ = "https://obftax.baltimorecountymd.gov/(S(m15cp5mubgqql1yzzjrxez45))/Default.aspx"
Dim Html As New HTMLDocument
Dim elem As Object, sVal$, payload As Variant
sVal = "01-01-350000"
payload = "RetryCounter=0&Action=MainMenu&ParcelType=RE&ParcelID=" & sVal & "&ParcelAddress=&PageNumber=1&SearchType=ParcelID&SearchParcel=" & sVal & "&SearchTaxNumber=&SearchStreetNumber=&SearchStreetName="
With CreateObject("MSXML2.XMLHTTP")
.Open "POST", Url, False
.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36"
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.Send payload
Html.body.innerHTML = .responseText
End With
Set elem = Html.querySelector("#tvrMessage")
If Not elem Is Nothing Then
MsgBox elem.innerText
Else:
MsgBox "failed to parse"
End If
End Sub
How can I scrape the text from the yellow colored area using vba making use of xmlhttp requests?
解决方案
推荐阅读
- docker - docker run 失败并显示“docker:来自守护进程的错误响应:地址已在使用中。”
- css - 生成具有单色的css渐变
- python - VS Code pylint(import-error)“无法导入”自定义目录中的子模块
- mysql - 如何选择几行运行总计
- unity3d - 在 Unity 中保存和加载整个场景
- f# - 如何指定 F# 函数签名的结果类型?
- performance - 自托管 AMP 框架 - 性能方面
- azure-cdn - 为自定义域启用 HTTPS 时,Azure CDN 失败并显示“不允许该操作”
- java - 使用 Spring Boot 自动装配任何接口
- matrix - 使用 Eigen 进行 Cholesky 分解