Themilkybarkid
New Member
- Joined
- Jan 27, 2020
- Messages
- 2
Hi all,
I am trying to parse a table from a website. I have used similar code successfully in the past but when using it to scrape this particular website it returns some odd data. Having inspected the web page the data I want is located within the td tags as expected but I can't figure out why the VBA code isn't reading it properly.
All help and feedback welcome
Many thanks
Sub RetrieveData()
Dim myurl As String
Dim TDElement As Object
Dim TDElements As IHTMLElementCollection
Dim IE As MSXML2.XMLHTTP60
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLBody As MSHTML.HTMLBody
Dim k As Long
Dim j As Long
Dim l As Long
Dim sht As Worksheet
ThisWorkbook.Sheets("Sheet1").Range("B3:L300").ClearContents
Set IE = New MSXML2.XMLHTTP60
Set HTMLDoc = New MSHTML.HTMLDocument
Set HTMLBody = HTMLDoc.body
myurl = "Market Data | EPEX SPOT"
IE.Open "GET", myurl, False
IE.send
On Error Resume Next
HTMLDoc.body.innerHTML = IE.responseText
Flat = False
k = 0
j = 3
Set TDElements = HTMLDoc.getElementsByTagName("td")
For Each TDElement In TDElements
ThisWorkbook.Sheets("Sheet1").Cells(j, k + 2) = TDElement.innerText
k = k + 1
If k = 7 Then j = j + 1
If k = 7 Then k = 0
Next
End Sub
I am trying to parse a table from a website. I have used similar code successfully in the past but when using it to scrape this particular website it returns some odd data. Having inspected the web page the data I want is located within the td tags as expected but I can't figure out why the VBA code isn't reading it properly.
All help and feedback welcome
Many thanks
Sub RetrieveData()
Dim myurl As String
Dim TDElement As Object
Dim TDElements As IHTMLElementCollection
Dim IE As MSXML2.XMLHTTP60
Dim HTMLDoc As MSHTML.HTMLDocument
Dim HTMLBody As MSHTML.HTMLBody
Dim k As Long
Dim j As Long
Dim l As Long
Dim sht As Worksheet
ThisWorkbook.Sheets("Sheet1").Range("B3:L300").ClearContents
Set IE = New MSXML2.XMLHTTP60
Set HTMLDoc = New MSHTML.HTMLDocument
Set HTMLBody = HTMLDoc.body
myurl = "Market Data | EPEX SPOT"
IE.Open "GET", myurl, False
IE.send
On Error Resume Next
HTMLDoc.body.innerHTML = IE.responseText
Flat = False
k = 0
j = 3
Set TDElements = HTMLDoc.getElementsByTagName("td")
For Each TDElement In TDElements
ThisWorkbook.Sheets("Sheet1").Cells(j, k + 2) = TDElement.innerText
k = k + 1
If k = 7 Then j = j + 1
If k = 7 Then k = 0
Next
End Sub