《2018年5月25日》【连续227天】
标题:BeautifulSoup的基本元素,HTML内容的遍历方法;
内容:
A.在某种意义上,
html文档<->标签树<->BeautifulSoup类
Tag,标签:
name, Attributes,NavigableString,Comment;
B,html中,有三种遍历方法,
包括下行遍历,上行遍历,平行遍历;
下行遍历:
.contents, .children , .descendants
上行遍历:
soup =BeautifulSoup(demo,"html.parser")
for parent in soup.a.parents:
if parent is None:
print(parent)
else:
print(parent.name)
平行遍历:
.next_sibling
.previous_sibling
.next_siblings
.previous_siblings