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

回答編集履歴

1

追記

2018/08/06 09:24

投稿

LouiS0616
LouiS0616

スコア35678

answer CHANGED
@@ -3,4 +3,16 @@
3
3
  found = li.find('a')
4
4
  if found is not None:
5
5
  print(found.text)
6
- ```
6
+ ```
7
+
8
+ ---
9
+ BeautifulSoupを利用されているという仮定の下で追記します。
10
+
11
+ selectメソッドを用いれば、li要素直下のa要素だけを抽出できます。
12
+ ```Python
13
+ for a_elem in soup.select('li > a'):
14
+ print(a_elem.text)
15
+ ```
16
+
17
+ スクレイピングをする以上はこういうのを自力で調べる能力も大事です。
18
+ [Beautiful Soup 4.2.0 Doc. 日本語訳](http://kondou.com/BS4/#)