Skip to content

Instantly share code, notes, and snippets.

Created February 21, 2020 14:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# -*- coding: utf-8 -*-
from bs4 import BeautifulSoup
# HTMLデータを取得する
html = """
<li class="best1"><td class><p class="waku">グリム童話</p><p class="waku">怖い話が多い</p></td><tr>
<li class="best2"><td class><p class="waku">ギリシャ神話</p><p class="waku">神々の名前が漫画のキャラに使われていたりする</p></td><tr>
# HTMLをBeautifulSoupに渡して解析
soup = BeautifulSoup(html, 'html.parser')
# h2タグのwakuクラスの部分のみ取り出したい
str = soup.find("li", class_="best2")
strs = str.find_all("p", class_="waku")
# 画面に表示
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment