ChromeDriverのheadlessモードによるスクレイピング
今まで
- windows
- phantomjs
を使ってスクレイピングをしてきたが、phantomjsの開発が終わったため?
chromedriverを使いたいという声が上がってきた。
chromedriverのheadlessモードを使うまでの手順を書く。
前提
- windows
- chromedriverをダウンロードしている
chromedriverをダウンロードしていなければ公式へ
ダウンロードしてきた「chromedriver.exe」を任意の場所へ格納。
(本記事では実行ファイルと同じフォルダに配置)
from selenium import webdriver from selenium.webdriver.chrome.options import Options options = Options() options.add_argument('--headless') driver = webdriver.Chrome(chrome_options=options, executable_path='chromedriver.exe') url = "target_url" driver.get(url)