Please correct my Hpricot troubles.

Discussion in 'Ruby' started by Jesse Crockett, Nov 1, 2008.

  1. 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/HpricotCssSearch

    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=#{query}&fulltext=Search").read)

    # 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
    --
    Posted via http://www.ruby-forum.com/.
    Jesse Crockett, Nov 1, 2008
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. joon
    Replies:
    1
    Views:
    511
    Roedy Green
    Jul 8, 2003
  2. Dan

    correct or not correct?

    Dan, Oct 2, 2003, in forum: HTML
    Replies:
    7
    Views:
    433
  3. KK
    Replies:
    2
    Views:
    525
    Big Brian
    Oct 14, 2003
  4. J.Ram
    Replies:
    7
    Views:
    641
  5. Jose Boza
    Replies:
    5
    Views:
    119
    Jose Boza
    Sep 5, 2007
Loading...

Share This Page