简体   繁体   English

Nokogiri方法问题(HTML)

[英]Nokogiri methods question (HTML)

I would like to find specific html tags using nokogiri. 我想使用nokogiri查找特定的html标签。 For example - I would like to find all the tags in a page I got, and all the tags in this page. 例如-我想在我得到的页面中找到所有标签,以及该页面中的所有标签。 Is it possible? 可能吗?

Finding every tag in a page is easy. 查找页面中的每个标签都很容易。

require 'nokogiri'

html = <<EOT
<html>
  <head>
    <title> the title </title>
  </head>
  <body>
    <p>the paragraph</p>
  </body>
</html>
EOT

doc = Nokogiri::HTML(html)
doc.search('*').each do |n|
  puts n.name
end

>> html
>> head
>> title
>> body
>> p

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM