Hi,
I am new in data scrape via VBA. I want to get my order history over amazon.
I can get all the info from html table with the code below. However, this code gives td elements in a single and it is hard to parse it again.
I attached the html code of web page and highlight the info I want to get with red rectangle.
Could you please help me.
Thanks
https://imgur.com/a/6WXnisW
I am new in data scrape via VBA. I want to get my order history over amazon.
I can get all the info from html table with the code below. However, this code gives td elements in a single and it is hard to parse it again.
I attached the html code of web page and highlight the info I want to get with red rectangle.
Could you please help me.
Thanks
https://imgur.com/a/6WXnisW
Code:
Sub ParseTable()
Dim IE As InternetExplorer
Dim htmldoc As MSHTML.IHTMLDocument 'Document object
Dim eleColtr As MSHTML.IHTMLElementCollection 'Element collection for tr tags
Dim eleColtd As MSHTML.IHTMLElementCollection 'Element collection for td tags
Dim eleRow As MSHTML.IHTMLElement 'Row elements
Dim eleCol As MSHTML.IHTMLElement 'Column elements
Dim ieURL As String 'URL
'Open InternetExplorer
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
'Navigate to webpage
ieURL = "Add URL"
IE.navigate ieURL
'Wait
Do While IE.Busy Or IE.readyState <> 4
DoEvents
Loop
Set htmldoc = IE.document 'Document webpage
Set eleColtr = htmldoc.getElementsByTagName("tr") 'Find all tr tags
MsgBox "Akin"
'This section populates Excel
i = 0 'start with first value in tr collection
For Each eleRow In eleColtr 'for each element in the tr collection
Set eleColtd = htmldoc.getElementsByTagName("tr")(i).getElementsByTagName("td") 'get all the td elements in that specific tr
j = 0 'start with the first value in the td collection
For Each eleCol In eleColtd 'for each element in the td collection
Sheets("Sheet1").Range("A1").Offset(i, j).Value = eleCol.innerText 'paste the inner text of the td element, and offset at the same time
j = j + 1 'move to next element in td collection
Next eleCol 'rinse and repeat
i = i + 1 'move to next element in td collection
Next eleRow 'rinse and repeat
End Sub