Reputation: 715
I am trying to use Nokogiri to scrape a web page. Right now, I am able to set a variable links to the following on a web page:
links = page.css('.item_inner')
and links is a:
Nokogiri::XML::NodeSet
Then I iterate through this NodeSet(links):
links.each{|link| puts link.css('.details a')}
In order to get some more information. But now the method above's class is now a:
Fixnum
and returns a list of (I'm not sure exactly what they are returning but it looks like a list of these:
<a se:clickable:target="true" href="/nyc/sale/1056207-coop-150-sullivan-street-soho-new-york?featured=1">150 Sullivan Street #34</a>
Now I know that there are key/value pairs within this but I am unable to access them at this point. How can I access say the href here and the actual name?
Upvotes: 0
Views: 767
Reputation: 535138
Once you have a single link as a node, its href is link['href']
and so forth, and the link text ("150 Sullivan Street") is its content
.
NOTE: A css
search always yields what is effectively an array of found nodes (actually a NodeSet). If you are quite sure that there is only one of something to be found by your search, you can skip past that by using at_css
instead, thus yielding a single node.
Upvotes: 1