前提・実現したいこと
pythonによるseleniumを用いたスクレイピングで画像の部分のURLを取得したいのですが
やたらと長い出力が帰ってきてしまいます。
どこが間違っているのか教えていただきたいです。
発生している問題・エラーメッセージ
Traceback (most recent call last): File "c:/Users/81801/Desktop/python/スクレイピング/競馬情報取得2R1.py", line 15, in <module> search_bar = driver.find_element_by_xpath('//dd/ul/li/a')[1] TypeError: 'WebElement' object is not subscriptable
該当のソースコード
python3
1#selenium 2 3#ライブラリ取得 4from selenium import webdriver 5from time import sleep 6from selenium.webdriver.chrome.options import Options 7 8#URL取得 9options = Options() 10options.add_argument('--headless') 11driver = webdriver.Chrome(r"C:\Users\81801\Desktop\python\chromedriver_win32\chromedriver",options=options) 12driver.get('https://race.netkeiba.com/top/race_list.html?kaisai_date=20200802&kaisai_id=2020040204¤t_group=1020200801#racelist_top_a') 13 14#検索 15search_bar = driver.find_element_by_xpath('//dd/ul/li/a')[1] 16print(search_bar.get_attribute('href')) 17 18
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。