回答編集履歴

1

回答修正

2019/04/15 00:06

投稿

can110
can110

スコア38266

test CHANGED
@@ -2,15 +2,31 @@
2
2
 
3
3
  `<html><div hoge="huga">~`をページソース例とした場合、以下のようにして属性`hoge`の値`huga`を取得できます。
4
4
 
5
+ 参考:
6
+
7
+ [Python】get_attribute・・・属性名から属性値を取得する](http://www.seleniumqref.com/api/python/element_infoget/Python_get_attribute.html)
8
+
5
- 参考:[PythonのBeautifulSoupで取得した要素(タグ)の属性値を抽出](https://qiita.com/chokosuki4400/items/2318437b3ae88d024b0f)
9
+ [PythonのBeautifulSoupで取得した要素(タグ)の属性値を抽出](https://qiita.com/chokosuki4400/items/2318437b3ae88d024b0f)
6
10
 
7
11
  ```Python
8
-
9
- from bs4 import BeautifulSoup
10
12
 
11
13
  # 略
12
14
 
13
15
  driver.get("https://~")
16
+
17
+
18
+
19
+ # 方法1
20
+
21
+ e = driver.find_element_by_tag_name('div')
22
+
23
+ print(e.get_attribute('hoge')) # huga
24
+
25
+
26
+
27
+ # 方法2
28
+
29
+ from bs4 import BeautifulSoup
14
30
 
15
31
  html = BeautifulSoup(driver.page_source,"lxml")
16
32