質問編集履歴

1

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

2021/08/01 06:07

投稿

sarusnnn
sarusnnn

スコア1

test CHANGED
File without changes
test CHANGED
@@ -16,7 +16,7 @@
16
16
 
17
17
  ### 該当のソースコード
18
18
 
19
-
19
+ エラーが出た箇所は次の箇所です
20
20
 
21
21
  ```python
22
22
 
@@ -27,6 +27,84 @@
27
27
  if len(title):
28
28
 
29
29
  print(str(cnt)+":"+title[0].text())
30
+
31
+ ```
32
+
33
+ 全体のコードは次のようになります
34
+
35
+ ```ここに言語を入力
36
+
37
+ from typing import Container
38
+
39
+ import urllib.request
40
+
41
+ from selenium.webdriver.chrome.options import Options
42
+
43
+ from selenium import webdriver
44
+
45
+ from time import sleep, time
46
+
47
+
48
+
49
+ options = Options()
50
+
51
+ options.add_argument('--headless')
52
+
53
+
54
+
55
+
56
+
57
+ driver = webdriver.Chrome('C:/Users/ユーザー名/Downloads/chromedriver_win32/chromedriver',chrome_options=options)
58
+
59
+
60
+
61
+ driver.get('https://abema.tv/timetable')
62
+
63
+ sleep(10)
64
+
65
+ driver.find_element_by_xpath("//button[contains(text(),'19歳以下')]").click()
66
+
67
+ driver.find_element_by_xpath("//button[contains(text(),'男性')]").click()
68
+
69
+ driver.find_element_by_xpath("//button[contains(text(),'次へ')]").click()
70
+
71
+ sleep(10)
72
+
73
+ driver.find_element_by_class_name("com-genre-survey-GenreSurveyCard__text").click()
74
+
75
+ driver.find_element_by_xpath("//button[contains(text(),'完了')]").click()
76
+
77
+ sleep(10)
78
+
79
+ category=driver.find_element_by_xpath("//a[@class='com-timetable-ChannelIconHeader__channel-link com-a-Link com-a-Link--dim']")
80
+
81
+ img=category.find_elements_by_xpath("picture/img")
82
+
83
+ if len(img):
84
+
85
+ src=img[0].get_attribute('src')
86
+
87
+ urllib.request.urlretrieve(src,"img.png")
88
+
89
+ category.click()
90
+
91
+ sleep(10)
92
+
93
+ timetable=driver.find_elements_by_xpath("//div[@class='com-timetable-TimetableItem__wrapper']")
94
+
95
+ cnt=0
96
+
97
+ for item in timetable:
98
+
99
+ cnt+=1
100
+
101
+ #タイトル
102
+
103
+ title=item.find_elements_by_xpath("div[1]/div/p/span/div/span")[0].get_attribute("innerHTML").text()
104
+
105
+ if len(title):
106
+
107
+ print(str(cnt)+":"+title)
30
108
 
31
109
  ```
32
110