我该如何实现? (我不使用rails,所以我不能使用它的消毒方法,我不想使用消毒宝石’因为我想黑名单删除不是白名单)
HTML = open(url)doc = Nokogiri::HTML(HTML.read)doc.CSS('.post').each do |post|puts post.to_send=> <p><span >bla bla <a href="http://torrentfreak.com/netflix-is-killing-bittorrent-in-the-us-110427/">statistica</a> blabla</span></p>
我想要它
=> <p><span>bla bla <a href="http://torrentfreak.com/netflix-is-killing-bittorrent-in-the-us-110427/">statistica</a> blabla</span></p>解决方法
require 'nokogiri'HTML = '<p ><span >bla bla</span></p>'doc = Nokogiri::HTML(HTML)doc.xpath('//@style').removeputs doc.CSS('.post')#=> <p ><span>bla bla</span></p>
编辑显示您可以调用NodeSet#remove
而不必使用.each(&:remove).
请注意,如果您有documentFragment而不是document,则Nokogiri有a longstanding bug,其中从片段中进行搜索不会按预期的方式工作.解决方法是使用:
doc.xpath('@style|.//@style').remove总结
以上是内存溢出为你收集整理的html – 带nokogiri的条带样式属性全部内容,希望文章能够帮你解决html – 带nokogiri的条带样式属性所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)