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')
参考:https://stackoverflow.com/questions/5418201/how-can-one-replace-an-element-with-text-in-lxml#answer-5420500