立即学习:https://edu.youkuaiyun.com/course/play/24756/280699?utm_source=blogtoedu
from bs4 import BeautifulSoup
html=""" """
soup = BeautifulSoup(html,"lxml")
(1)contents:
head_tag=soup.head
print(head_tag.contents)
(2)children(迭代器):
print(head_tag.children)
for i in head_tag.children:
print(i)
(3)strings:
for string in soup.strings:
print(string)(带有空格)
(4)stripped_strings:
for string in soup.stripped_strings:
print(string)(去掉多余空白)