R
R.. Kumar 1.9.1 OSX
I am trying to access some particular children in a document. I find
myself having to loop (several levels) through children checking name ==
"xxx". I am wondering whething there is more direct way of getting the
same. Here's a simple sample.
I am trying to get the href of a class called prevnext (on browser it is
"next").
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open('http://www.reddit.com/r/programming/'))
nextlink = nil
doc.css('p.nextprev').each do |link|
link.children.each do |child|
if child.name == "a"
nextlink = child.attributes["href"].value
end
end
end
puts nextlink
myself having to loop (several levels) through children checking name ==
"xxx". I am wondering whething there is more direct way of getting the
same. Here's a simple sample.
I am trying to get the href of a class called prevnext (on browser it is
"next").
require 'nokogiri'
require 'open-uri'
doc = Nokogiri::HTML(open('http://www.reddit.com/r/programming/'))
nextlink = nil
doc.css('p.nextprev').each do |link|
link.children.each do |child|
if child.name == "a"
nextlink = child.attributes["href"].value
end
end
end
puts nextlink