Hi all,
I'm new here from Hong Kong. I'm working on getting web data to Excel 2003 project. During the course, I came across another forum searching for related info. URL: http://www.excelforum.com/excel-pro...must-have-javascript-enabled.html#post3820062 This post was about getting data from a website Fantastic Fiction A guy name Chippy posted the solution code (copied from the forum to below). This code is working fine; however, my question is how to figure out this line
"Set contentDiv = HTMLdoc.getElementById("ffcontent")"
where ffcontent didn't appear on the source codes, innerHTML/text, outerHTML/text etc (from what I knew).
Any idea???
Code copied from http://www.excelforum.com/
Public Sub Get_New_Books()
Dim HTMLdoc As HTMLDocument, HTMLdocTemp As HTMLDocument
Dim contentDiv As HTMLDivElement
Dim bookTable As HTMLTable
Dim r As Integer
Dim destCell As Range
Dim URL As String
Dim lines As Variant
Set destCell = ActiveSheet.Range("A1")
destCell.Parent.Cells.Clear
URL = "http://www.fantasticfiction.co.uk/new-books/"
Set HTMLdocTemp = New HTMLDocument
Set HTMLdoc = HTMLdocTemp.createDocumentFromUrl(URL, "")
While HTMLdoc.readyState <> "complete": DoEvents: Wend
Do
DoEvents
Set contentDiv = HTMLdoc.getElementById("ffcontent")
Loop Until contentDiv.getElementsByTagName("TABLE").Length > 0
r = 0
For Each bookTable In contentDiv.getElementsByTagName("TABLE")
destCell.Offset(r, 0).Value = bookTable.Rows(0).Cells(0).innerText
lines = Split(bookTable.Rows(0).Cells(2).innerText, vbCrLf)
destCell.Offset(r, 1).Resize(1, UBound(lines) + 1).Value = lines
r = r + 1
Next
End Sub
I'm new here from Hong Kong. I'm working on getting web data to Excel 2003 project. During the course, I came across another forum searching for related info. URL: http://www.excelforum.com/excel-pro...must-have-javascript-enabled.html#post3820062 This post was about getting data from a website Fantastic Fiction A guy name Chippy posted the solution code (copied from the forum to below). This code is working fine; however, my question is how to figure out this line
"Set contentDiv = HTMLdoc.getElementById("ffcontent")"
where ffcontent didn't appear on the source codes, innerHTML/text, outerHTML/text etc (from what I knew).
Any idea???
Code copied from http://www.excelforum.com/
Public Sub Get_New_Books()
Dim HTMLdoc As HTMLDocument, HTMLdocTemp As HTMLDocument
Dim contentDiv As HTMLDivElement
Dim bookTable As HTMLTable
Dim r As Integer
Dim destCell As Range
Dim URL As String
Dim lines As Variant
Set destCell = ActiveSheet.Range("A1")
destCell.Parent.Cells.Clear
URL = "http://www.fantasticfiction.co.uk/new-books/"
Set HTMLdocTemp = New HTMLDocument
Set HTMLdoc = HTMLdocTemp.createDocumentFromUrl(URL, "")
While HTMLdoc.readyState <> "complete": DoEvents: Wend
Do
DoEvents
Set contentDiv = HTMLdoc.getElementById("ffcontent")
Loop Until contentDiv.getElementsByTagName("TABLE").Length > 0
r = 0
For Each bookTable In contentDiv.getElementsByTagName("TABLE")
destCell.Offset(r, 0).Value = bookTable.Rows(0).Cells(0).innerText
lines = Split(bookTable.Rows(0).Cells(2).innerText, vbCrLf)
destCell.Offset(r, 1).Resize(1, UBound(lines) + 1).Value = lines
r = r + 1
Next
End Sub