I am trying to scrape Project Gutenberg.
I am able to use the .getElementsByClassName("chapter") to get the divs that hold the chapters. However, I am unable to get all the elements in that div as a collection that I would then be able to iterate over.
Sub getZ()
Dim H As Object, C As New DataObject, stryn&, cptr%, html As New HTMLDocument, p As HTMLHtmlElement, para As Object, i&
Set H = CreateObject("WinHTTP.WinHTTPRequest.5.1")
Application.ScreenUpdating = False
With H
.SetAutoLogonPolicy 0
.SetTimeouts 0, 0, 0, 0
.Open "GET", "https://www.gutenberg.org/files/8164/8164-h/8164-h.htm", False
.Send
.WaitForResponse
End With
html.body.innerHTML = H.ResponseText
Set para = html.getElementsByClassName("chapter").getElementsByTagName("*")
i = 1
For Each p In para
Worksheets("Output").Range("A" & i & "") = p.innerText
i = i + 1
Next
Application.ScreenUpdating = True
End Sub
I am getting an error with getElementsByTagName("*") as the object doesn't support that method.