Vote count:
0
I'm using nokogiri
to screenscapre contents of a websites.
I set fetch_number
to specify the number of divs that I want to retrieve. For example, I may want the first(10) tweets from the target page.
Code looks like this:
doc.css(".tweet").first(fetch_number).each do |item|
title = item.css("a")[0]['title']
end
However, when there is less than 10 match div
returned, it will reports NoMethodError: undefined method 'css' for nil:NilClass
. This is because when no match html found, it will return nil
.
How can I make it return the all available data within 10? I don't need the nil
s.
asked 24 secs ago
Rails: Find within the first 10?
Aucun commentaire:
Enregistrer un commentaire