开发者

Removing the <script> elements of an HTML

开发者 https://www.devze.com 2022-12-15 16:03 出处:网络
I\'m using Ruby, with the Nokogiri module, and i want to get the content of the body without the script elements.

I'm using Ruby, with the Nokogiri module, and i want to get the content of the body without the script elements.

Nokogiri parse uses XPATH or CSS 3.0. XPATH i really dont understand, and i can't find the 开发者_如何学PythonCSS selector to achieve my goals.


I don't think such selection is possible with XPath.

I'm not that familiar with Ruby or Nokogiri, but based on answers to a similar question, you might want to try selecting all script elements from the HTML document and removing them.

doc = Nokogiri::HTML(your_html)
doc.xpath("//script").remove

Adjust accordingly.

0

精彩评论

暂无评论...
验证码 换一张
取 消