VBA - Scraping a Web Page Problem

LarsLarsen

New Member
Joined
Jul 20, 2015
Messages
2
Hey,

I'm trying to obtain the id's of rows in a table on a website (the url is in the code). My problem is that I can't find the table. When I run the code it tells me that only one table exist, and that is not the one I'am looking for. Can someone please explain to me why it only returns the last table?

If for any need the XPath of the table is (google chrome): //*[@id="fs-fixtures"]/table/tbody

Best regards
Lars

Code:
Sub BrowseTableIds()
    Dim XMLPage As New MSXML2.XMLHTTP60
    Dim HTMLDoc As New MSHTML.HTMLDocument
    Dim HTMLTables As MSHTML.IHTMLElementCollection
    Dim HTMLTable As MSHTML.IHTMLElement
    
    XMLPage.Open "GET", "http://www.flashscore.dk/fodbold/england/premier-league/kommende/", False
    XMLPage.send
    
    HTMLDoc.body.innerHTML = XMLPage.responseText
    
    Set HTMLTables = HTMLDoc.getElementsByTagName("table")
    
    For Each HTMLTable In HTMLTables
         Debug.Print HTMLTable.ID, HTMLTable.className
    Next HTMLTable


    Debug.Print HTMLTables.Length
End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top