Sub ヤフートップをスクレイピング()
Dim document As Object: Set document = CreateObject("htmlfile")
With CreateObject("MSXML2.ServerXMLHTTP")
.Open "GET", "https://www.yahoo.co.jp/"
.send
Do While .readyState < 4
DoEvents
Loop
document.body.innerHTML = .responseText
If .Status <> 200 Then
Debug.Print .Status
Exit Sub
End If
End With
Dim i As Integer
Dim target As Object: Set target = document.querySelector("main article section ul").getElementsByTagName("li")
For i = 0 To target.Length - 1
Debug.Print target(i).textContent
Debug.Print target(i).getElementsByTagName("a")(0).href
Debug.Print
Next
Set document = Nothing
Set httpReq = Nothing
End Sub