1条回答 默认 最新
- 普通网友 2016-10-05 09:06关注
storyp1p1p1
b1b1b1aa
p4p4p4
'''from lxml import html
tree = html.fromstring(doc)
a = tree.get_element_by_id("a1")
print(html.tostring(a))
print(html.tostring(tree).decode())def dropnode(e=None):
if e is None: return
if e.tag == 'body': return
nd = e.getnext()
while nd is not None:
nd.drop_tree()
nd = e.getnext()
dropnode(e.getparent())dropnode(a)
print(html.tostring(tree).decode())本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报