0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

DeprecationWarning: executable_path has been deprecated, please pass in a Service object browser = webdriver.Chrome(CHROME_DRIVER, options=options)の解決

Last updated at Posted at 2021-11-01

#スクレイピングのこと

このコードだと

scraping.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

CHROME_BIN = "/usr/bin/chromium-browser"
CHROME_DRIVER = '/usr/lib/chromium-browser/chromedriver'

options = Options()
options.binary_location = CHROME_BIN
options.add_argument('--headless')

browser = webdriver.Chrome(CHROME_DRIVER, options=options)
browser.get("https://www.google.co.jp")
print(browser.title)
browser.quit()
結果
scraping.py:15: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  browser  = webdriver.Chrome(CHROME_DRIVER, options=options)
Google

というワーニングがでる。
以下の修正でそれが解消される。

scraping2.py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

# Options
CHROME_DRIVER = '/usr/lib/chromium-browser/chromedriver'
options = Options()
options.headless = True
service = Service(CHROME_DRIVER)

browser = webdriver.Chrome(options=options, service=service)
browser.get('https://google.com')
print(browser.title)
browser.quit()
結果
Google

ついでにbinary_locationを指定する意図が何か他にあるとして、スクレイピングするだけならbinary_locationの指定は不要で動いた。
そのためchromium-chromedriverをインストールすればchromium-browserも不要で動く。

0
0
2

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?