BeautifulSoup相关的用法

from bs4 import BeautifulSoup html = \'\'\' <html><head><title>The Dormouse\'s story</title></head> <body> <p><b>The Dormouse\'s story</b></p> <p>Once upon a time there were three little sisters; and their names were <a href="http://example.com/elsie">Elsie</a>, <a href="http://example.com/lacie">Lacie</a> and <a href="http://example.com/tillie">Tillie</a>; and they lived at the bottom of a well.</p> <p>...</p> \'\'\' soup = BeautifulSoup(html, "lxml") print(soup.prettify())
print(soup.title)
print(soup.title.name)
print(soup.title.string)
print(soup.title.parent.name)
print(soup.p)
print(soup.p["class"])
print(soup.a)
print(soup.find_all(\'a\'))
print(soup.find(id=\'link3\'))

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zwsxfz.html