2019年4月4日木曜日

MacにChrome webdriveのインストール方法

Pythonでseleniumを使ってみようと思ったら、以下のソースコードを実行してみたら、WebDriverのパスが見つからないのエラーができました。→ 「
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
#encoding:utf-8
from selenium import webdriver
 
browser = webdriver.Chrome()
browser.get('http://google.co.jp')
調べたところ、まずChrome webdriveをインストールしておくが必要でした。
chromedriveのオフィシャルサイトInstall SafariDriver on macOS からダウンロードし、とりあえず$HOME/Download/直下に置きました。
ソースコードを以下のように修正し、問題なく実行できました。
※「executable_path」に、先程ダウンロードしたファイルの場所を入れる
※ もし必要であれば、chromedriver の実行権限も変更
#encoding:utf-8
from selenium import webdriver
 
browser = webdriver.Chrome(executable_path='$HOME/Download/chromedriver')
browser.get('http://google.co.jp')

上記することで、以下の2つのエラーを解消できました。
selenium.common.exceptions.WebDriverException: Message: 'library' executable may have wrong permissions for ChromeDriver
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

2018年8月30日木曜日

gitリモートブランチチェックアウトする方法

以下のコマンドを使えば、リモートにある「remote_branch_name」というブランチをローカル「local_branch_name」としてチェックアウトできます。
git checkout -b local_branch_name origin/remote_branch_name