Ariel
Ariel

Reputation: 2808

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?

Upvotes: 0

Views: 275

Answers (1)

the Tin Man
the Tin Man

Reputation: 160551

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

Upvotes: 1

Related Questions