【问题标题】:how to remove html element's style attribute using Hpricot?如何使用 Hpricot 删除 html 元素的样式属性?
【发布时间】:2010-06-18 02:31:05
【问题描述】:

像这样:

<p style="font-size: 12pt;">
  Hello world
  <span style="font-weight: bold;">just do it</span>
</p>

我想删除每个元素的“样式”属性。我想要这样的结果:

<p>Hello world <span>just do it</span></p>

如何使用 hpricot 做到这一点?

谢谢。


好的,我已经解决了这个问题,如下所示:

doc = Hpricot("<p style='xxx'>are you ok?</p>")

doc.search("[@style]").each do |e|
  e.remove_attribute("style")
end

【问题讨论】:

    标签: html ruby hpricot


    【解决方案1】:

    有时写入堆栈溢出会自动解决您的问题 :)(我的经验表明)

    【讨论】:

      猜你喜欢
      • 2013-11-16
      • 2015-03-03
      • 2023-03-25
      • 1970-01-01
      • 2010-11-05
      • 1970-01-01
      • 2017-08-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多