簡體   English   中英

Nokogiri方法問題(HTML)

[英]Nokogiri methods question (HTML)

我想使用nokogiri查找特定的html標簽。 例如-我想在我得到的頁面中找到所有標簽,以及該頁面中的所有標簽。 可能嗎?

查找頁面中的每個標簽都很容易。

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