Forum: Ruby Please correct my Hpricot troubles.

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.
F6baf14eb750a1ae9f050bc579516d15?d=identicon&s=25 Jesse Crockett (tefflox)
on 2008-11-01 14:39
Hello, I need some help using hpricot.  I'm trying simply to print out
the each link within "ul.class-name" for a CSV file.

ref: http://code.whytheluckystiff.net/hpricot/wiki/Hpri...

sample source for search "butter oil":

<ul class='mw-search-results'>

<li><a href="/wiki/Coconut_oil" title="Coconut oil">Coconut <span
class='searchmatch'>oil</span></a> ...

<li><a href="/wiki/Cocoa_butter" title="Cocoa butter">Cocoa <span
class='searchmatch'>butter</span></a></li>

</ul>


ruby:

search = "corn+flakes
bananas
milk+lowfat
blueberries+raw"

search = search.split("\n")

a = 0; until a == 3

  query = search[a]

  doc =
Hpricot(URI.parse("http://en.wikipedia.org/wiki/Special:Search?search...)

  # grab report list to build from (I need an array of inner html per
link)
  doc = (doc/"ul.mw-search-results a")
  line = "#{a + 1}|#{query}|"

  begin

    #
      line << ???  # fails for all attempts, please help here
    #

  rescue
    printf "%i|%s\n", a + 1, "## Exception Caught ##"
  end
  sleep 8 # + rand(20) # to avoid
  a += 1
end
This topic is locked and can not be replied to.