html - 未找到用于解析的 HTML 响应中的表
问题描述
我正在发送一个 POST 请求,并确认存在预期的数据。
尝试从该响应文本 (HTML) 解析表时,VBA 找不到任何表。
Option Explicit
Sub GetExchangeRates()
Dim XMLPage As New MSXML2.XMLHTTP60
Dim htmlDoc As New MSHTML.HTMLDocument
Dim URL As String
URL = "http://www.medmouic.org/Advanced/TrouverAdv"
XMLPage.Open "POST", URL, False
XMLPage.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
XMLPage.setRequestHeader "Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"
XMLPage.send "imonumber=&val=0&Name=&selectFlag=333&selectType=&grossfrom=&grossTo=&yearFrom=&yearTo=&selectClass=&Countries=Selects+items&InspectResult=All&TypesDeficiencies=0&SortBy=Imo&fro=01.08.2019&to=31.08.2019"
SaveHTMFile XMLPage.responseText
htmlDoc.body.innerHTML = XMLPage.responseText
ProcessHTMLPage htmlDoc
End Sub
Sub ProcessHTMLPage(HTMLPage As MSHTML.HTMLDocument)
Dim HTMLTable As MSHTML.IHTMLElement
Dim HTMLTables As MSHTML.IHTMLElementCollection
Dim HTMLRow As MSHTML.IHTMLElement
Dim HTMLCell As MSHTML.IHTMLElement
Dim RowNum As Long, ColNum As Integer
Set HTMLTables = HTMLPage.getElementsByTagName("table")
For Each HTMLTable In HTMLTables
Debug.Print HTMLTable.className
Next HTMLTable
End Sub
“SaveHTMFile XMLPage.responseText”创建了一个 TXT 文件,我可以在其中找到该表。我期待“Debug.Print HTMLTable.className”显示表的类“data-table”,但结果却一无所获。
<form method="post" action="/Advanced/TrouverAdv" id='myform'>
<table class="data-table" id="anyTable" >
<!--- Sortby IMONUMBER---->
<thead>
<tr bgcolor="#428bca">
<th>IMO Number</th>
<th>Ship Name</th>
<th>Flag state</th>
<th>Date of inspection</th>
<th>Place of inspection</th>
</tr>
</thead>
<tbody>
<tr>
<td>
9301433
</td>
解决方案
推荐阅读
- reactjs - 我的带有 nestjs、reactjs 和 firebase 的应用程序太慢了
- python - 我想交换 x 轴和 y 轴并将此图更改为水平图 python
- python - 如何从角图中隐藏一维直方图?
- c# - Blazor Web 程序集在每个请求中发送数据
- swift - Swiftui 中的汉堡导航菜单幻灯片动画
- vscode-settings - vscode如何通过命令打开设置界面
- python - 使用 OpenCV 检测作业中的水平线
- python - 如何将mongodb连接到python?
- angular - 如何在没有 Ngif 或单击功能的情况下以角度调用 Ts 函数?
- react-native - 我想用 React Native 中的按钮移动屏幕