前提・実現したいこと
pythonでseleniumを用いて,abemaの番組タイトルの取得を行おうとコードを組んでいたところ,TypeError: 'str' object is not callableといったエラーが生じてしまいました。
発生している問題・エラーメッセージ
TypeError: 'str' object is not callable
該当のソースコード
エラーが出た箇所は次の箇所です
python
1#タイトル 2 title=item.find_elements_by_xpath("div[1]/div/p/span/div/span") 3 if len(title): 4 print(str(cnt)+":"+title[0].text())
全体のコードは次のようになります
from typing import Container import urllib.request from selenium.webdriver.chrome.options import Options from selenium import webdriver from time import sleep, time options = Options() options.add_argument('--headless') driver = webdriver.Chrome('C:/Users/ユーザー名/Downloads/chromedriver_win32/chromedriver',chrome_options=options) driver.get('https://abema.tv/timetable') sleep(10) driver.find_element_by_xpath("//button[contains(text(),'19歳以下')]").click() driver.find_element_by_xpath("//button[contains(text(),'男性')]").click() driver.find_element_by_xpath("//button[contains(text(),'次へ')]").click() sleep(10) driver.find_element_by_class_name("com-genre-survey-GenreSurveyCard__text").click() driver.find_element_by_xpath("//button[contains(text(),'完了')]").click() sleep(10) category=driver.find_element_by_xpath("//a[@class='com-timetable-ChannelIconHeader__channel-link com-a-Link com-a-Link--dim']") img=category.find_elements_by_xpath("picture/img") if len(img): src=img[0].get_attribute('src') urllib.request.urlretrieve(src,"img.png") category.click() sleep(10) timetable=driver.find_elements_by_xpath("//div[@class='com-timetable-TimetableItem__wrapper']") cnt=0 for item in timetable: cnt+=1 #タイトル title=item.find_elements_by_xpath("div[1]/div/p/span/div/span")[0].get_attribute("innerHTML").text() if len(title): print(str(cnt)+":"+title)
試したこと
title=item.find_elements_by_xpath("div[1]/div/p/span/div/span")[0].text print(str(cnt)+":"+title)
title=item.find_elements_by_xpath("div[1]/div/p/span/div/span")[0].get_attribute("innerHTML").text() print(str(cnt)+":"+title)
等を行っても同じエラーが生じました
補足情報(FW/ツールのバージョンなど)
Python 3.9.5
selenium 3.141.0
ChromeDriver 92.0.4515.107

回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/08/01 06:59