Qiitaの記事を参考にして、pythonのseleniumに挑戦してみようとしたのですが、うまくいきません。
記事内の「最初のスクレイピング 一番簡単な基本」というところまでしたのですが、エラーが出てしまいます。
実行したのは以下のコードです。
import time from selenium import webdriver # 仮想ブラウザ起動、URL先のサイトにアクセス driver = webdriver.Chrome() driver.get('https://www.google.com/') time.sleep(2) # サイト内から検索フォームを探す。 # Googleでは検索フォームのNameが「q」です。 el = driver.find_element_by_name("q") # 検索フォームに文字を入力 el.send_keys('Qiitaで記事投稿楽しいぞ!!!') time.sleep(2) # 検索フォーム送信(Enter) el.submit() from bs4 import BeautifulSoup soup = BeautifulSoup(driver.page_source, features="html.parser") # タイトルをターミナル上に表示 print(soup.title.string) ```大量にエラーが出ているのでわかりにくいのですが、最後に selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home とあることから、chromedriverの場所にパスが通っていないと言われているようです。しかし、このエラーを見てからパスを通したのですが(記事通り、とりあえず C:\Users\ユーザー名\local\bin にchromedriver.exeファイルをおいていて、そこにパスを通しました)同じエラーが出ます。 教えていただけると嬉しいです。 エラーの全文も載せておきます Traceback (most recent call last): File "C:\Users\ユーザー名\Anaconda3\lib\site-packages\selenium\webdriver\common\service.py", li ne 76, in start stdin=PIPE) File "C:\Users\ユーザー名\Anaconda3\lib\subprocess.py", line 756, in __init__ restore_signals, start_new_session) File "C:\Users\ユーザー名\Anaconda3\lib\subprocess.py", line 1155, in _execute_child startupinfo) FileNotFoundError: [WinError 2] 指定されたファイルが見つかりません。 During handling of the above exception, another exception occurred: Traceback (most recent call last): File ".\facebook_scraping.py", line 5, in <module> driver = webdriver.Chrome() File "C:\Users\ユーザー名\Anaconda3\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__ self.service.start() File "C:\Users\ユーザー名\Anaconda3\lib\site-packages\selenium\webdriver\common\service.py", li ne 83, in start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PA TH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/05/11 06:34