接続元のIPアドレスを隠してスクレイピングを行いたい場合などは、公開Proxyを使う方法の他にTorを使って行う方法があります。
Tor本体をダウンロード
以下のURLからTor本体をダウンロードしてきます。
バージョンが上がると頻繁にリンク切れを起こすので直リンクは置きません。
以下のURLにアクセスし一番新しいバージョンより1つ前くらいのフォルダを選択してください。
一番新しいバージョンのものはベータ版で目的のファイルがありません。
Index of /torbrowser


中略(割と下から辿ったほうが早いところにあります)

tor-browser-win….zip ではなく、
tor-win??-バージョン文字列.zip を探してきてダウンロードします。
任意のディレクトリに解凍して tor.exe を実行しておけばOKです。
下記の例では
C:\tools\Tor
に配置しています。
Torネットワークが起動すると Socks5 127.0.0.1:9050 にてアクセスができます。

ChromeにてTor経由でWebにアクセスする
ChromeDriverの起動時にオプションを指定してSocks5を使う設定をします。
(proxy-serverの行)
下記のサンプルでは、プライベートブラウジングモードも指定しています。
(incognitoの行)
Option Explicit
Sub main()
With New ChromeDriver
.AddArgument "--proxy-server=socks5://localhost:9050"
.AddArgument "--incognito"
.Get "http://taruo.net/e/"
MsgBox "!"
End With
End Sub

Tor経由でGoogle検索を行う
以下のコードを実行
Option Explicit
Sub main()
Dim driver As New ChromeDriver
With driver
.AddArgument "--proxy-server=socks5://localhost:9050"
.AddArgument "--incognito"
'非表示
'.AddArgument "--headless"
'画像を読み込ませない
'.AddArgument "--blink-settings=imagesEnabled=false"
.Get "https://google.co.jp/"
ClickElementByTagText driver, "div", "同意する"
.Wait 300
.FindElementByName("q").Clear
.FindElementByName("q").SendKeys "SeleniumBasic"
.Wait 1000
.FindElementByTag("form").Submit
MsgBox "ロボットチェックを手動でクリアしたらOKをクリック"
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
Sub ClickElementByTagText(obj As Object, tag As String, txt As String)
Dim elmLoop As WebElement
For Each elmLoop In obj.FindElementsByTag(tag)
If elmLoop.Text = txt Then
elmLoop.Click
Exit For
End If
Next
End Sub
実行結果
「私はロボットではありません」チェックに引っかかると思うので、手動でクリアさせます。

検索結果が表示されます。

Visual Basicのイミディエイトウィンドウに結果が表示されています。
SeleniumBasicをインストールしてExcel(VBA)からWeb ... https://lil.la/archives/3436 -------------------------------------------------- Seleniumbasic - GitHub Pages https://florentbr.github.io/SeleniumBasic/ -------------------------------------------------- Excel VBAでSeleniumBasicを使わずにスクレイピングする https://qiita.com/uezo/items/66e20b064ffd5f239b9a -------------------------------------------------- 非エンジニアにこそ伝えたいSeleniumBasic | ツナググループHC https://www.indival.co.jp/2018/02/07/5918/ -------------------------------------------------- ノート】WEBブラウザを自動操作する!Selenium Basicの ... https://hirachin.com/post-5019/ -------------------------------------------------- 【VBA】Seleniumリファレンス(逆引き)【まとめ】 https://nkmrdai.com/vba-selenium-reference/ -------------------------------------------------- EXCEL VBAでプログラミング SeleniumBasicを使ったWeb ... http://kensyou-d.info/selenium.html -------------------------------------------------- VBAのスクレイピングを簡単楽にしてくれるSelenium https://excel-ubara.com/excelvba4/EXCEL_VBA_401.html -------------------------------------------------- Excel+SeleniumBasicでChrome操作・スクレイピング https://take-web.com/task_help/msoffice/excel/seleniumbasicc/ -------------------------------------------------- Selemium Basic VBA用ドキュメントの日本語訳メモ https://curio-shiki.com/blog/vba/selemium-basic-vba-documentation --------------------------------------------------
コメント