質問するログイン新規登録

質問編集履歴

1

全体のコードを追加しました

2021/08/01 06:07

投稿

sarusnnn
sarusnnn

スコア1

title CHANGED
File without changes
body CHANGED
@@ -7,14 +7,53 @@
7
7
  ```
8
8
 
9
9
  ### 該当のソースコード
10
-
10
+ エラーが出た箇所は次の箇所です
11
11
  ```python
12
12
  #タイトル
13
13
  title=item.find_elements_by_xpath("div[1]/div/p/span/div/span")
14
14
  if len(title):
15
15
  print(str(cnt)+":"+title[0].text())
16
16
  ```
17
+ 全体のコードは次のようになります
18
+ ```ここに言語を入力
19
+ from typing import Container
20
+ import urllib.request
21
+ from selenium.webdriver.chrome.options import Options
22
+ from selenium import webdriver
23
+ from time import sleep, time
17
24
 
25
+ options = Options()
26
+ options.add_argument('--headless')
27
+
28
+
29
+ driver = webdriver.Chrome('C:/Users/ユーザー名/Downloads/chromedriver_win32/chromedriver',chrome_options=options)
30
+
31
+ driver.get('https://abema.tv/timetable')
32
+ sleep(10)
33
+ driver.find_element_by_xpath("//button[contains(text(),'19歳以下')]").click()
34
+ driver.find_element_by_xpath("//button[contains(text(),'男性')]").click()
35
+ driver.find_element_by_xpath("//button[contains(text(),'次へ')]").click()
36
+ sleep(10)
37
+ driver.find_element_by_class_name("com-genre-survey-GenreSurveyCard__text").click()
38
+ driver.find_element_by_xpath("//button[contains(text(),'完了')]").click()
39
+ sleep(10)
40
+ category=driver.find_element_by_xpath("//a[@class='com-timetable-ChannelIconHeader__channel-link com-a-Link com-a-Link--dim']")
41
+ img=category.find_elements_by_xpath("picture/img")
42
+ if len(img):
43
+ src=img[0].get_attribute('src')
44
+ urllib.request.urlretrieve(src,"img.png")
45
+ category.click()
46
+ sleep(10)
47
+ timetable=driver.find_elements_by_xpath("//div[@class='com-timetable-TimetableItem__wrapper']")
48
+ cnt=0
49
+ for item in timetable:
50
+ cnt+=1
51
+ #タイトル
52
+ title=item.find_elements_by_xpath("div[1]/div/p/span/div/span")[0].get_attribute("innerHTML").text()
53
+ if len(title):
54
+ print(str(cnt)+":"+title)
55
+ ```
56
+
18
57
  ### 試したこと
19
58
  次のサイト(https://stackoverflow.com/questions/55488606/typeerror-str-object-is-not-callable-using-selenium-through-python)を参考にし
20
59
  ```