Python で Firefox を操作する時は、geckodriver が必要になる。
ダウンロードしたら、/usr/local/bin に入れておく(または、任意の場所に入れてPATHを通しておく)。
Firefox Developer Edition.app をダウンロードしておくとよい。
↓こちらはテストコード
from selenium import webdriver from selenium.webdriver.firefox.options import Options # ブラウザーを起動 opts = Options() opts.binary_location = '/Applications/Firefox Developer Edition.app/Contents/MacOS/firefox' # opts.headless = True driver = webdriver.Firefox(options=opts) # Google検索画面にアクセス driver.get('https://www.google.co.jp/') # htmlを取得・表示 html = driver.page_source # print(html) # ブラウザーを終了 driver.quit()
DeprecationWarning: use options instead of chrome_options (or firefox_options) のエラーが出たら、
driver = webdriver.Chrome(chrome_options=options)
ではなく
driver = webdriver.Chrome(options=options)
にする
Firefox の デフォルト のプロファイルフォルダーの場所は、
~/Library/Application Support/Firefox/Profiles