try:
from BeautifulSoup import BeautifulSoup
except ImportError:
from bs4 import BeautifulSoup
#example of json data (dictionary)
data = {
"url":"www.example.com",
"content" : "<!DOCTYPE html><html><body><h1>My First Heading</h1><strong>My first paragraph.</strong></body></html>"
}
#html parser
soup = BeautifulSoup(data["content"], "html.parser")
#get all the tags of one type
print(soup.find_all("h1"))
print(soup.find_all("strong"))
您将得到一个标签列表,如:
[<h1>My First Heading</h1>]
[<strong>My first paragraph.</strong>]
您可以尝试以下方法:
您将得到一个标签列表,如:
要安装bs4,请执行以下操作:
我希望有帮助
相关问题 更多 >
编程相关推荐