简体   繁体   中英

Nokogiri methods question (HTML)

I would like to find specific html tags using nokogiri. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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