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

質問編集履歴

2

コード書き替え

2021/08/14 11:50

投稿

guhehehehell
guhehehehell

スコア1

title CHANGED
File without changes
body CHANGED
@@ -5,14 +5,15 @@
5
5
 
6
6
  elme = driver.find_elements_by_tag_name("h2")
7
7
 
8
+ for elem in elme:
8
- elme.find_elements_by_tag_name("a").get_attribute("href")```
9
+ elem_url = elme.find_element_by_tag_name("a").get_attribute("href")
9
10
 
10
11
  エラー
11
- ---------------------------------------------------------------------------
12
+
12
13
  AttributeError Traceback (most recent call last)
13
- <ipython-input-155-34f7b1a3bbb9> in <module>
14
+ <ipython-input-182-68bf6960063c> in <module>
14
- 1 elme = driver.find_elements_by_tag_name("h2")
15
15
  2
16
+ 3 for elem in elme:
16
- ----> 3 elme.find_elements_by_tag_name("a").get_attribute("href")
17
+ ----> 4 elem_url = elme.find_element_by_tag_name("a").get_attribute("href")
17
18
 
18
- AttributeError: 'list' object has no attribute 'find_elements_by_tag_name'
19
+ AttributeError: 'list' object has no attribute 'find_element_by_tag_name'

1

複数取得に変更

2021/08/14 11:50

投稿

guhehehehell
guhehehehell

スコア1

title CHANGED
File without changes
body CHANGED
@@ -1,7 +1,8 @@
1
1
  スクレイピングの練習をしていますがhrefの抜き出しがうまくできません。
2
2
  解決方法を教えていただきたいです。
3
+ 複数のhrefを抜き出したいです。
3
4
 
4
- ```ここに言語を入力
5
+
5
6
  elme = driver.find_elements_by_tag_name("h2")
6
7
 
7
8
  elme.find_elements_by_tag_name("a").get_attribute("href")```