extract value of the hpricot elem

J

Junkone

url="http://www.nasdaq.com/aspxcontent/shortinterests.aspx?
symbol=FRE&selected=FRE"
doc=open(url) {|f| Hpricot(f)}
doc.search("//table[@class='dataGrid']")
rqTable=doc.search("//table[@class='dataGrid']")
rqTable.search('tr').each{|tr|

tdArray=tr.search('td')

dataArray=Array.new
#tr.search('td').each{|td|
# puts td.inner_text
# }

puts tdArray[0].class,tdArray[1].to_s,tdArray[2]
puts "end"
}


how do i get the text value of the tdArray[0] which is internally a
Hpricot::Elem
 
M

Mark Thomas

 url="http://www.nasdaq.com/aspxcontent/shortinterests.aspx?
symbol=FRE&selected=FRE"
doc=open(url) {|f| Hpricot(f)}
doc.search("//table[@class='dataGrid']")
rqTable=doc.search("//table[@class='dataGrid']")
rqTable.search('tr').each{|tr|

tdArray=tr.search('td')

        dataArray=Array.new
        #tr.search('td').each{|td|
        #       puts td.inner_text
        #       }

        puts tdArray[0].class,tdArray[1].to_s,tdArray[2]
        puts "end"

}

how do i get the text value of the tdArray[0] which is internally a
Hpricot::Elem

It's often easier to simply go directly to what you want with XPath.
I'm not sure exactly what you want to extract, but try this:


require 'open-uri'
url="http://www.nasdaq.com/aspxcontent/shortinterests.aspx?
symbol=FRE&selected=FRE"
doc=Hpricot(open(url))
rqTable=doc.search("//table[@class='dataGrid']//td/text()")
puts rqTable.inspect
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top