I am moving some of my scraping from JavaScript to Ruby, and I am having trouble using Nokogiri.
I have trouble getting the right <dl>
in a target class. I tried using css
and xpath
with the same result.
This is a sample of the HTML:
<div class="target">
<dl>
<dt>A:</dt>
<dd>foo</dd>
<dt>B:</dt>
<dd>bar</dd>
</dl>
</div>
This is a sample of my code:
require 'rubygems'
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open(url))
doc.css(".target > dl").each do |item|
puts item.text # I would expect to receive a collection of nodes here,
# yet I am receiving a single block of text
end
doc.css(".target > dl > dt").each do |item|
puts item.text # Here I would expect to iterate through a collection of
# dt elements, however I receive a single block of text
end
Can someone show me what I am doing wrong?