移除標簽的兩種方式
可以用xpath定位
for bad in html.xpath(".//table"):
bad.getparent().remove(bad)
參考:https://stackoverflow.com/questions/7981840/how-to-remove-an-element-in-lxml
直接刪除相關標簽
在使用xpath獲取指定標簽后,直接刪除。
etree.strip_elements(f, 'r')
for bad in html.xpath(".//table"):
bad.getparent().remove(bad)
參考:https://stackoverflow.com/questions/7981840/how-to-remove-an-element-in-lxml
在使用xpath獲取指定標簽后,直接刪除。
etree.strip_elements(f, 'r')
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。