newbie-question: Type Conversion

Discussion in 'Ruby' started by M P, Mar 8, 2008.

  1. M P

    M P Guest

    I am using the Hpricot(which is awesome!) ruby module to do screen
    scraping. When I retrieve a list of search results, it returns a
    custom data type "Hpricot::Elements." I am trying to treat this
    returned list as an array, but keep getting errors. How can I convert
    this to an array of my results? I have tried '.to_a' but that doesn't
    work.


    Thank You for your time. Here is a code example:

    doc = Hpricot(open("my url"))
    @conts = doc.search("form[@name='form']/div")
     
    M P, Mar 8, 2008
    #1
    1. Advertising

  2. M P

    M P Guest

    Nevermind, I figured it out with:

    @conts.methods.each { |x|
    puts "******************************" #for readability
    puts x
    puts "******************************"
    }
     
    M P, Mar 8, 2008
    #2
    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. luna
    Replies:
    1
    Views:
    6,823
  2. ibiza
    Replies:
    2
    Views:
    5,353
    ibiza
    Jan 27, 2006
  3. Chris
    Replies:
    2
    Views:
    21,346
    Chris
    May 11, 2006
  4. Anton Lauridsen
    Replies:
    2
    Views:
    430
    Anton Lauridsen
    Dec 5, 2004
  5. Michal Nazarewicz

    conversion from const type* to type* allowed?

    Michal Nazarewicz, Jan 4, 2007, in forum: C Programming
    Replies:
    13
    Views:
    565
    Eric Sosman
    Jan 5, 2007
Loading...

Share This Page