Googleの検索結果をスクレイピングしようとしてHTMLソースを確認すると、膨大な意味不明のコードに遭遇することになります。
以下のVBA(Excel VBA)コードで簡単に検索結果を取得できます。
Google検索から結果を取得するVBA(Excelマクロ)コード
Sub WEBスクレピングテスト()
Dim elmLoop As WebElement
With New ChromeDriver
.Get "https://www.google.com/search?q=SeleniumBasic"
For Each elmLoop In .FindElementsByTag("A")
If elmLoop.FindElementsByTag("H3").Count Then
Debug.Print elmLoop.FindElementByTag("H3").Text
Debug.Print , elmLoop.Attribute("HREF")
Debug.Print "--------------------------------------------------"
End If
Next
End With
End Sub
実行結果



コメント