質問編集履歴
3
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,11 +52,11 @@
|
|
52
52
|
|
53
53
|
while page_number <= page_number_max:
|
54
54
|
|
55
|
-
class_group = driver.find_elements_by_class_name("rc")
|
55
|
+
class_group = driver.find_elements_by_class_name("rc")
|
56
56
|
|
57
57
|
for class_name in class_group:
|
58
58
|
|
59
|
-
title_list.append(class_name.find_element_by_class_name("LC20lb DKV0Md"))
|
59
|
+
title_list.append(class_name.find_element_by_class_name("LC20lb DKV0Md").text)
|
60
60
|
|
61
61
|
url_list.append(class_name.find_element_by_tag_name("a").get_attribute("href"))
|
62
62
|
|
@@ -64,13 +64,13 @@
|
|
64
64
|
|
65
65
|
|
66
66
|
|
67
|
-
if driver.find_elements_by_
|
67
|
+
if driver.find_elements_by_id("pnnext") == []: #次のページがなかったらループを抜け出す
|
68
68
|
|
69
69
|
page_number = page_number_max + 1
|
70
70
|
|
71
71
|
else:
|
72
72
|
|
73
|
-
next_page = driver.find_elements_by_
|
73
|
+
next_page = driver.find_elements_by_id("pnnext").get_attribute("href")
|
74
74
|
|
75
75
|
driver.get(next_page)
|
76
76
|
|
@@ -142,9 +142,9 @@
|
|
142
142
|
|
143
143
|
> 引用テキスト
|
144
144
|
|
145
|
-
DevTools listening on ws://127.0.0.1:49
|
145
|
+
DevTools listening on ws://127.0.0.1:49835/devtools/browser/d77618c9-a3d6-4982-814e-034bac32c200
|
146
146
|
|
147
|
-
[1
|
147
|
+
[9312:13168:1219/164828.980:ERROR:device_event_log_impl.cc(211)] [16:48:28.980] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: システムに接続されたデバイスが機能していません。 (0x1F)
|
148
148
|
|
149
149
|
Traceback (most recent call last):
|
150
150
|
|
@@ -154,7 +154,7 @@
|
|
154
154
|
|
155
155
|
File "C:\Users\yagla\Program_lessons\Python\index.py", line 24, in search_page
|
156
156
|
|
157
|
-
title_list.append(class_name.find_element_by_class_name("LC20lb DKV0Md"))
|
157
|
+
title_list.append(class_name.find_element_by_class_name("LC20lb DKV0Md").text)
|
158
158
|
|
159
159
|
File "C:\Users\yagla\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 398, in find_element_by_class_name
|
160
160
|
|
@@ -178,6 +178,4 @@
|
|
178
178
|
|
179
179
|
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".LC20lb DKV0Md"}
|
180
180
|
|
181
|
-
|
182
|
-
|
183
181
|
(Session info: chrome=87.0.4280.88)
|
2
コンソールに書かれている情報を追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -137,3 +137,47 @@
|
|
137
137
|
|
138
138
|
|
139
139
|
```
|
140
|
+
|
141
|
+
実行すると以下のように出力されます。
|
142
|
+
|
143
|
+
> 引用テキスト
|
144
|
+
|
145
|
+
DevTools listening on ws://127.0.0.1:49192/devtools/browser/ed2754e1-b7b2-4f70-9563-6e9ebf346065
|
146
|
+
|
147
|
+
[14264:7080:1219/163616.006:ERROR:device_event_log_impl.cc(211)] [16:36:16.005] USB: usb_device_handle_win.cc:1020 Failed to read descriptor from node connection: システムに接続されたデバイスが機能していません。 (0x1F)
|
148
|
+
|
149
|
+
Traceback (most recent call last):
|
150
|
+
|
151
|
+
File "C:\Users\yagla\Program_lessons\Python\index.py", line 38, in <module>
|
152
|
+
|
153
|
+
titles, urls, count= search_page(driver)
|
154
|
+
|
155
|
+
File "C:\Users\yagla\Program_lessons\Python\index.py", line 24, in search_page
|
156
|
+
|
157
|
+
title_list.append(class_name.find_element_by_class_name("LC20lb DKV0Md"))
|
158
|
+
|
159
|
+
File "C:\Users\yagla\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 398, in find_element_by_class_name
|
160
|
+
|
161
|
+
return self.find_element(by=By.CLASS_NAME, value=name)
|
162
|
+
|
163
|
+
File "C:\Users\yagla\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 658, in find_element
|
164
|
+
|
165
|
+
return self._execute(Command.FIND_CHILD_ELEMENT,
|
166
|
+
|
167
|
+
File "C:\Users\yagla\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
|
168
|
+
|
169
|
+
return self._parent.execute(command, params)
|
170
|
+
|
171
|
+
File "C:\Users\yagla\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
|
172
|
+
|
173
|
+
self.error_handler.check_response(response)
|
174
|
+
|
175
|
+
File "C:\Users\yagla\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
|
176
|
+
|
177
|
+
raise exception_class(message, screen, stacktrace)
|
178
|
+
|
179
|
+
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".LC20lb DKV0Md"}
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
(Session info: chrome=87.0.4280.88)
|
1
コードの修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,13 +52,13 @@
|
|
52
52
|
|
53
53
|
while page_number <= page_number_max:
|
54
54
|
|
55
|
-
class_group = driver.find_elements_by_name("rc") #クラス名だけ探す
|
55
|
+
class_group = driver.find_elements_by_class_name("rc") #クラス名だけ探す
|
56
56
|
|
57
57
|
for class_name in class_group:
|
58
58
|
|
59
|
-
title_list.append(class_name.find_element_by_name("LC20lb DKV0Md"))
|
59
|
+
title_list.append(class_name.find_element_by_class_name("LC20lb DKV0Md"))
|
60
60
|
|
61
|
-
url_list.append(class_name.find_element_by_name("a").get_attribute("href"))
|
61
|
+
url_list.append(class_name.find_element_by_tag_name("a").get_attribute("href"))
|
62
62
|
|
63
63
|
scraping_count += 1
|
64
64
|
|