给定一个Nokogiri::XML::Node
对象,我该如何删除它的一些dom节点?例如,假设我有一个innerHtml
为:
hello world <b>this is in bold face</b> <div>this is inside a div</div> bye bye
如何删除<div>
元素并获取Nokogiri::XML::Node
所在的innerHtml
对象:
hello world <b>this is in bold face</b> bye bye
答案 0 :(得分:1)
找到<div>
并在其上调用remove
。例如:
>> node.to_html
=> "<div>hello world <b>this is in bold face</b> <div>this is inside a div</div> bye bye</div>"
>> node.at('div').remove; node.to_html
=> "<div>hello world <b>this is in bold face</b> bye bye</div>"