首页 > 解决方案 > 未找到用于解析的 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>

标签: htmlvbahttpparsingpost

解决方案


推荐阅读