LoginSignup
0
4

More than 3 years have passed since last update.

Windows 10 + Python3 + selenium + geckodriver で headless Firefox を試してみる

Last updated at Posted at 2020-06-10

目的

Windows 10 + Python3 + selenium + geckodriver で headless Firefox を試してみる

WebDriverのインストール

WebDriverより geckodriver-v0.26.0-win64.zip をダウンロード後
適藤なフォルダに解凍する -> C:\Dev\Tools\geckodriver-win64
上記のフォルダを環境変数に登録する

python用のパッケージをインストールする


> pip3 install selenium

サンプルコード

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

# ブラウザーを起動
options = Options()
options.binary_location = 'C:\\Program Files\\Mozilla Firefox\\firefox.exe'
options.add_argument('-headless')
driver = webdriver.Firefox(options=options)

# Google検索画面にアクセス
driver.get('https://www.google.co.jp/')

# htmlを取得・表示
html = driver.page_source
print(html)

# ブラウザーを終了
driver.quit()

参考にしたサイトはこちら

WebDriver
Seleniumブラウザー自動化プロジェクト > WebDriver > ドライバー要件
【Python】SeleniumでHeadless Firefoxを使おう
Selenium Python(ABC順)

0
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
4