Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 67497

VBA - HTML Parsing HTTP Response

$
0
0

I have been trying to parse a very simple HTML response but without success so far.

The HTTP POST request seems to work as required but then no results.

Public Sub parsehtml()

Dim http As Object, html As New HTMLDocument, vessels As Object, titleElem As Object, detailsElem As Object, vessel As HTMLHtmlElement
Dim i As Integer

Set http = CreateObject("MSXML2.XMLHTTP")
http.Open "POST", "http://www.medmouic.org/Home/Trouver", False
http.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
http.send "imonumber=&val=0&Name=&selectFlag=333&selectType=&date1=01.08.2019&date2=31.08.2019"
html.body.innerHTML = http.responseText
Debug.Print http.responseText
Set vessels = html.getElementsByTagName("tbody")

i = 2
    For Each vessel In vessels
        Set titleElem = vessel.getElementsByClassName("tr")(0)
            Folha1.Cells(i, 1).Value = titleElem.getElementsByTagName("td")(0).innerText
            Folha1.Cells(i, 2).Value = titleElem.getElementsByTagName("span")(0).href
            Folha1.Cells(i, 3).Value = titleElem.getElementsByTagName("span")(0).innerText
            'Sheets(1).Cells(i, 4).Value = detailsElem.getElementsByTagName("a")(0).innerText
    i = i + 1
Next

End Sub

And the HTML looks like this:

<table class="data-table" id="anyTable">
.......
        <tbody>
            <tr>
                <td class="sub">
                    9301433

                </td>
                <td class="sub">

                   BOMAR CAEN
                </td>
                <td class="sub">
                    Portugal
                </td>
                <td class="sub">
                    Containership
                </td>
                <td class="sub">

                    <span class="label label label-success"  alt="show details " title="show details ">
                        <a href="/Home/AfficherRapport?rapportID=84883" style="color:white; background-color:#58D3F7">30.08.2019</a>
                    </span>
                </td>
                <td class="sub"> Malta</td>
            </tr>   
        </tbody>

The objective is to get the innertext inside all those "SUB" classes.


Viewing all articles
Browse latest Browse all 67497

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>