标签:
from bs4 import BeautifulSoup soup = BeautifulSoup(html_doc) print(soup.prettify()) # <html> soup.title # <title>The Dormouse‘s story</title> soup.title.name # u‘title‘ soup.title.string # u‘The Dormouse‘s story‘ soup.title.parent.name # u‘head‘ soup.p # <p class="title"><b>The Dormouse‘s story</b></p> soup.p[‘class‘] # u‘title‘ soup.a # <a class="sister" href="http://example.com/elsie" id="link1">Elsie</a> soup.find_all(‘a‘) # [<a class="sister" href="http://example.com/elsie" id="link1">Elsie</a>, # <a class="sister" href="http://example.com/lacie" id="link2">Lacie</a>, # <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>] soup.find(id="link3") # <a class="sister" href="http://example.com/tillie" id="link3">Tillie</a>
标签:
原文地址:http://www.cnblogs.com/liuqimin/p/5244228.html