1
一個文檔所有的父母我有一個這樣的文件:提取物與引入nokogiri
<DL><a lot of tags>...<H3>Entry 1</H3><a lot of tags>...</DL>
<DL><a lot of tags>...<H3>Entry 2</H3><a lot of tags>...
<DL><a lot of tags>...<H3>Entry 21</H3><a lot of tags>...
<DL><a lot of tags>...<H3>Entry 211</H3><a lot of tags>...</DL>
</DL>
</DL>
<DL><a lot of tags>...><H3>Entry 3</H3><a lot of tags>...</DL>
我想找到所有'進入,很容易與後續代碼:
@doc=Nokogiri::HTML(@file)
@doc.css('DL>h3').each do |node| puts node.text end
怎麼能我提取H3父母的任何條目列表? 我想有一個方法爲「父」返回的關係,即: entry211.parent ==> /輸入2 /輸入21/