【问题标题】:Using nokogiri how do I remove all elements with a certain classname使用 nokogiri 如何删除具有特定类名的所有元素
【发布时间】:2019-07-27 19:05:00
【问题描述】:

我正在试验 Ruby 和 Nokogiri。

我已经弄清楚如何打开本地 html 文档并按类名选择节点:

require 'rubygems'                                                                                               
require 'nokogiri'                                                                                               

doc = Nokogiri::HTML(open("file"))                                                                          


puts doc.css('a.target') 

那么我如何在没有我选择的节点的情况下转储文档?

【问题讨论】:

标签: ruby nokogiri


【解决方案1】:

应该是:

doc.css('a.target').remove
puts doc.at('html').to_s

【讨论】:

    猜你喜欢
    • 2011-10-26
    • 1970-01-01
    • 2014-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-03
    • 2016-03-19
    • 1970-01-01
    相关资源
    最近更新 更多