Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7931687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:47:45+00:00 2026-06-03T20:47:45+00:00

I crawled a page and stored elements from the page into an array. If

  • 0

I crawled a page and stored elements from the page into an array.

If I inspect the first element:

puts "The inspection of the first my_listing: "
puts my_listing.first.first.inspect

The output is:

The inspection of the first my_listing: 
#<Nokogiri::XML::Element:0x80c58764 name="p" children=[#<Nokogiri::XML::Text:0x80c584e4 " May  4 - ">, #<Nokogiri::XML::Element:0x80c58494 name="a" attributes=[#<Nokogiri::XML::Attr:0x80c58340 name="href" value="http://auburn.craigslist.org/web/2996976345.html">] children=[#<Nokogiri::XML::Text:0x80c57f08 "residual income No experience is needed!!!">]>, #<Nokogiri::XML::Text:0x80c57da0 " - ">, #<Nokogiri::XML::Element:0x80c57d50 name="font" attributes=[#<Nokogiri::XML::Attr:0x80c57bfc name="size" value="-1">] children=[#<Nokogiri::XML::Text:0x80c577c4 " (online)">]>, #<Nokogiri::XML::Text:0x80c5765c " ">, #<Nokogiri::XML::Element:0x80c5760c name="span" attributes=[#<Nokogiri::XML::Attr:0x80c574b8 name="class" value="p">] children=[#<Nokogiri::XML::Text:0x80c57080 " img">]>]>

How do I access each element? For instance, how do I access the first Text element in this object which would be ‘May 4 – ‘?

If I do:

puts my_listing.first.first.text, 

I get this output:

May  4 - residual income No experience is needed!!! -  (online)  img

Also, how do I access the href attribute?

my_listing.first.first[:href]

which does not work.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T20:47:47+00:00Added an answer on June 3, 2026 at 8:47 pm

    Please note that Nokogiri treats everything as nodes – be it a text, attribute, or an element. Your document has one child:

    irb(main):014:0> my_listing.children.size
    => 1
    irb(main):015:0> puts my_listing.children
    <p> May 4 - <a href="http://auburn.craigslist.org/web/2996976345.html">residual income No
    experience is needed</a> - <font size="-1"> (online)</font> <span class="p">
    img</span></p>
    => nil
    

    By the way, puts uses to_s method, and that method assembles texts from all children – this is why you see more text than you want.

    If you go deeper to see the children of that single element, you have:

    irb(main):017:0> my_listing.children.first.children.size
    => 6
    irb(main):018:0> puts my_listing.children.first.children
     May 4 - 
    <a href="http://auburn.craigslist.org/web/2996976345.html">residual income No
    experience is needed</a>
     - 
    <font size="-1"> (online)</font>
    
    <span class="p"> img</span>
    => nil
    

    To get what you asking about, keep going down the hierarchy:

    irb(main):022:0> my_listing.children.first.children[0]
    => #<Nokogiri::XML::Text:0x..fd9d1210e " May 4 - ">
    irb(main):023:0> my_listing.children.first.children[0].text
    => " May 4 - "
    irb(main):024:0> my_listing.children.first.children[1]['href']
    => "http://auburn.craigslist.org/web/2996976345.html"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to put some sites i crawled into a shelve, but the shelve
Here's a code below which sends an email whenver any page is crawled by
It seems though Yahoo only indexes one of my urls (my home page) from
how can i download a web page from my web app, then reading title
I was trying to read a page from the same site using PHP. I
I used nutch 1.4 and crawled a website. I got the website crawled successfully
I have a webcrawler application. It successfully crawled most common and simple sites. Now
I have a crawler application (with C#) that downloads pages from web . The
I have implemented a web crawler that crawls and retrieves content from .edu TLD.
I am preparing to write my first web crawler, and it looks like Anemone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.