背景
以下を実行した
$ python {ファイル名}.py
すると
Traceback (most recent call last):
File "/〜/sele-tu.py", line 11, in <module>
search_box = driver.find_element_by_name('q') #ページ上の要素の取得
^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'WebDriver' object has no attribute 'find_element_by_name'
おや…?
どうやらSeleniumがVer.3 → 4 に上がる際に使えなくなった模様。
以下で解決しました。
変更前
search_box = driver.find_element_by_name('q') #ページ上の要素の取得
引数にまとめて書くやり方に統一される
変更後
from selenium.webdriver.common.by import By
search_box = driver.find_element(By.NAME, "q")
これでOK