Created
February 27, 2017 04:53
-
-
Save ysawa/8724832e11299d602d56e15e9bc2bdf2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
html = """ | |
<html> | |
<head></head> | |
<body> | |
<div id="todo"> | |
<h1>Todo list</h1> | |
<ul class="items"> | |
<li>hello world</li> | |
<li>hoge fuga</li> | |
<li>foo bar</li> | |
</ul> | |
</div> | |
""" | |
soup = BeautifulSoup(html, 'html.parser') | |
h1 = soup.select_one("div#todo > h1").string | |
print("h1 " + h1) | |
# Todo list | |
li_list = soup.select("div#todo li") | |
for li in li_list: | |
print(li.string) | |
# hello world | |
# hoge fuga | |
# foo bar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment