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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM