scrapingヘッドレス
間違っている場所あったら優しく教えてね
selenium をインストールする
$ pip3 install selenium Successfully installed selenium-3.141.0 $ pip3 show selenium Name: selenium Version: 3.141.0 Summary: Python bindings for Selenium Home-page: https://github.com/SeleniumHQ/selenium/
無事インストール完了
ChromeDriverをインストール
Python + Selenium で Chrome の自動操作を一通り - Qiita chromedriver-binary · PyPI
$ pip3 install chromedriver-binary Successfully installed chromedriver-binary-74.0.3729.6.0 $ pip3 show chromedriver-binary Name: chromedriver-binary Version: 74.0.3729.6.0 Summary: Installer for chromedriver. Home-page: https://github.com/danielkaiser/python-chromedriver-binary
インストール完了です
$ which chromedriver-path /Library/Frameworks/Python.framework/Versions/3.7/bin/chromedriver-path
PATHを通せ言われたがなんのことだかさっぱりわからず
- ChromeDriver をインストールする
Downloads - ChromeDriver - WebDriver for Chrome こちらからインストールした.zip ファイルがダウンロードされ解凍してPATHが通る場所へ移動させたい
$ echo $PATH /user/local/bin
があったのでここに移動する.mv コマンドでいけそうだがFInder操作をしました。
🍎 python $ python3 Chrome.py 1 Traceback (most recent call last): File "Chrome.py", line 8, in <module> driver = webdriver.Chrome() File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__ desired_capabilities=desired_capabilities) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__ self.start_session(capabilities, browser_profile) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session response = self.execute(Command.NEW_SESSION, parameters) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of ChromeDriver only supports Chrome version 74 (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Mac OS X 10.14.3 x86_64)
よくわからず.一旦終了
- 追記
This version of ChromeDriver only supports Chrome version 74 (Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Mac OS X 10.14.3 x86_64)
ここで問題が発生している.バージョンが違うらしい.
- chromedriverのバージョンを下げる方向で進めていくことにする.
https://chromedriver.storage.googleapis.com/index.html?path=73.0.3683.68/
今回はここから一つ下のバージョンのchromedriverをダウンロードする
前回ダウンロードしたchromedriverをアンインストールしました.その後同じ場所/usr/local/bin
に今取得したchromedriverを移動しました。
$ chromedriver ChromeDriver 73.0.3683.68 (47787ec04b6e38e22703e856e101e840b65afe72)
無事バージョンが下がりました.
実行したら無事画面が立ち上がりました.
# chrome.py import time from selenium import webdriver driver = webdriver.Chrome() driver.get('https://www.google.com/') time.sleep(5) search_box = driver.find_element_by_name("q") # 検索したいメッセージ search_box.send_keys('ChromeDriver') search_box.submit() time.sleep(5) driver.quit()