差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
selenium-webdriver [2025/01/13 02:24] skkselenium-webdriver [2025/02/22 16:07] (現在) skk
行 1: 行 1:
-= [[selenium-webdriver]] LM: [2025-01-13 02:24:51]+= [[selenium-webdriver]] LM: [2025-02-22 16:05:39]
 ~~NOCACHE~~ ~~NOCACHE~~
  
行 107: 行 107:
   * https://stackoverflow.com/questions/67551031/how-to-pass-desired-capabilities-to-undetected-chromedriver-with-selenium-python   * https://stackoverflow.com/questions/67551031/how-to-pass-desired-capabilities-to-undetected-chromedriver-with-selenium-python
   * https://stackoverflow.com/questions/72406597/how-to-avoid-bot-detection-on-websites-using-selenium-python   * https://stackoverflow.com/questions/72406597/how-to-avoid-bot-detection-on-websites-using-selenium-python
 +  * [2025-02-22] https://www.zenrows.com/blog/selenium-cloudflare-bypass
  
 === - undetected chromedriver [2023-09-07] === === - undetected chromedriver [2023-09-07] ===
行 120: 行 121:
  
 FreeBSD で動作させる為には,[[https://www.sakaki.works/doku/doku.php?id=selenium-webdriver#undetected-chromedriver_%E3%81%AE%E5%8B%95%E4%BD%9C%E8%A8%AD%E5%AE%9A_2023-09-07|下記]]参照. FreeBSD で動作させる為には,[[https://www.sakaki.works/doku/doku.php?id=selenium-webdriver#undetected-chromedriver_%E3%81%AE%E5%8B%95%E4%BD%9C%E8%A8%AD%E5%AE%9A_2023-09-07|下記]]参照.
 +
 +=== - seleniumbase [2025-02-22] ===
 +undetected_chromedriver は,2025/02 現在,あまりメンテされておらず,Cloudflare などの anti-bot システムで検知されがちなツールになってきている模様.
 +
 +ZenRow というクラウドサービスを使っても anti-bot の回避はできるようだが月額がまーまー高い.広告記事だと思うけど,この ZenRow の特集記事が良くできているので参考に読むと良い.
 +
 +今は,SeleniumBase というツールまたは,nodriver というツールが最近ではアクティブな模様.nodriver は undetected_chromedriver の作者が作っている後継だけど,selenium の書きにくいところと決別したいらしく,結構独自の書き方にしないといけなくて,既存のコードがある場合には導入しにくい.SeleniumBase は undetected_chromedriver を fork して独自進化させてるっぽいので,undetected_chromedriver からの乗り換えにはとても便利.
 +
 +また,multiprocessing 環境への対応を頑張った形跡が見られるのも嬉しい.undetected_chromedriver は,複数のプロセスを動かそうとすると,Text Busy と言われることがちょいちょいあった.これは,ChromeDriver を利用するたびに chromedriver をダウンロードしてきてパッチを当ててたので,複数プロセスで動かそうとすると,時々競合のような状態になっていたと想像している.
 +SeleniumBase は,初回起動時に uc_driver という,パッチを当てまくった chromedriver を作成して,以降は必要がなければずっとそれを使い続けるので,複数のプロセスから ChromeDriver(=uc_driver) を利用しても問題が起きない.
 +
 +さらに,undetected_chromedriver を FreeBSD で無理矢理動かしていた時は,zombie プロセスが大量に作成されてしまったので,定期的にプログラムを再起動してゾンビを殺していたが,終了処理などがきれいになっているのか,SeleniumBase だと zombie が発生しなかった.
 +
 +ということで,今から利用する場合は,SeleniumBase の方が全然良い.(nodriver ももしかしたら良いのかもしれないけど,試してはいない)
  
 === - UA について === === - UA について ===
行 154: 行 169:
  
 ====== - freebsd における tips  ====== ====== - freebsd における tips  ======
 +===== - SeleniumBase の動作設定 [2025-02-22] =====
 +SeleniumBase もソースコードないでは Linux への分岐しか対応してない.ただ,undetected_chromedriver は Linux バイナリをダウンロードしてきていたので,Linux Emulation しなければならなかったが,SeleniumBase は chromedriver に対してなんらかの方法でパッチを当てているので,FreeBSD でインストールできる Chromium に附属している chromedriver をベースにして動作する.つまり,linux emulation しなくても大丈夫.
 +
 +==== - python ライブラリの準備 ====
 +<code bash>
 +# pip install seleniumbase 
 +</code>
 +
 +==== - python ライブラリの FreeBSD 対応 ====
 +/usr/local/lib/python3.11/site-packages/seleniumbase/undetected  以下に,下記のファイルが存在している.
 +
 +<code>
 +__init__.py     cdp_driver      dprocess.py     patcher.py      webelement.py
 +__pycache__     cdp.py          options.py      reactor.py
 +</code>
 +
 +patecher.py で以下.
 +
 +<code python>
 +15c16
 +< IS_POSIX = sys.platform.startswith(("darwin", "cygwin", "linux"))
 +---
 +> IS_POSIX = sys.platform.startswith(("darwin", "cygwin", "linux", "freebsd"))
 +30c31
 +<     if sys_plat.endswith("linux"):
 +---
 +>     if sys_plat.endswith("linux") or sys_plat.endswith("freebsd"):
 +</code>
 +
 +/usr/local/lib/python3.11/site-packages/seleniumbase/fixtures/shared_utils.py というファイルでも OS 分岐を行なっていたので,ここでも Linux と同じ動作にしてしまう.
 +
 +<code python>
 +47 def is_linux():
 +48     return "linux" in sys.platform or "freebsd" in sys.platform
 +</code> 
 +
 +これで少なくとも,僕の環境では SeleniumBase が FreeBSD で動作している.
 +
 ===== - undetected-chromedriver の動作設定 [2023-09-07] ===== ===== - undetected-chromedriver の動作設定 [2023-09-07] =====
 undetected-chromedriver がダウンロードできるバイナリは上述の通りで,FreeBSD で動作させる為には,以下のどちらかの対応かと考えた. undetected-chromedriver がダウンロードできるバイナリは上述の通りで,FreeBSD で動作させる為には,以下のどちらかの対応かと考えた.
行 166: 行 219:
  
 ==== - python ライブラリの準備 ====  ==== - python ライブラリの準備 ==== 
-<code>+<code bash>
 # pip install undetected-chromedriver  # pip install undetected-chromedriver 
 </code> </code>
selenium-webdriver.1736702694.txt.gz · 最終更新: 2025/01/13 02:24 by skk
文書の先頭へ
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0