Forum: Ruby Hpricot problem with free text

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
06ca7bf5b4480fc2b272ab03f4c2ac3a?d=identicon&s=25 John Zoldiark (zoldiark)
on 2008-12-17 23:57
Hi and thanks for the help, I am new to ruby and I am trying to get some
data from a website using the Hpricot library.I am doing this: links =
Hpricot(index_page).search("td.det_movie").collect{ |link| link["href"]
} to get an array of data but the thing is that right now I need some
text out of tags and the previous version only works with tags.
This is the code that I am reading, and I need the part "The Day the
Earth Stood Still"

<a class="link" href="detalle_movie.php?mv_id=618">The Day the Earth
Stood Still</a>

thanks for any help
Ad97b577f331ae29ed90da5751f2e44f?d=identicon&s=25 Dan Diebolt (dandiebolt)
on 2008-12-18 00:32
(Received via mailing list)
require 'hpricot'

doc=Hpricot('<a class="link" href="detalle_movie.php?mv_id=618">The Day
the Earth Stood Still</a>')

doc.search("//a").each do |link|
  puts "#{link[:href]}"
  puts "#{link.inner_text}"
end
detalle_movie.php?mv_id=618
The Day the Earth Stood Still
3da512875f3295be2d577fa70b3493b4?d=identicon&s=25 Sebastian W. (globulus)
on 2008-12-18 01:00
Hi John,
I haven't used Hpricot much, but you may want to dig through the API
documentation a bit more. Also, why's website has a few good tutorials
on how to grab data in different ways.

I believe the method you want to be looking at is "innerHTML" (or some
such name).

HTH

John Zoldiark wrote:
> Hi and thanks for the help, I am new to ruby and I am trying to get some
> data from a website using the Hpricot library.I am doing this: links =
> Hpricot(index_page).search("td.det_movie").collect{ |link| link["href"]
> } to get an array of data but the thing is that right now I need some
> text out of tags and the previous version only works with tags.
> This is the code that I am reading, and I need the part "The Day the
> Earth Stood Still"
>
> <a class="link" href="detalle_movie.php?mv_id=618">The Day the Earth
> Stood Still</a>
>
> thanks for any help
06ca7bf5b4480fc2b272ab03f4c2ac3a?d=identicon&s=25 John Zoldiark (zoldiark)
on 2008-12-18 01:53
Thanks for the idea but I have already try innerHTML but is returning
the data but not in an array structure.  I need something similar to
innerHTML.collect or something like that.  I have read a lot of
documentation about Hpricot but I have not see something to fix my
problem.
This topic is locked and can not be replied to.