Beautifulsoup库之处理子标签、后代标签、兄弟标签、父标签

from bs4 import BeautifulSoup
soup=BeautifulSoup(html,"html.parser")

一,处理子标签和后代标签(children)

soup.find("table",{"class":"wap"}).children
# 后代标签
soup.find("table",{"class":"wap"}).descendants()

二,处理兄弟标签

soup.find("table",{"class":"wap"}).tr.next_siblings

soup.find({"class":"wap"}).next_siblings
# 返回单个标签
soup.find("table",{"class":"wap"}).tr.next_siblings


https://blog.csdn.net/m0_37324740/article/details/77886117

posted @ 2019-12-05 10:28  一种清孤不等闲  阅读(3139)  评论(0编辑  收藏  举报
Live2D