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 8027845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:56:17+00:00 2026-06-04T23:56:17+00:00

This is the page in question: http://phoenix.craigslist.org/cpg/ What I would like to do is

  • 0

This is the page in question: http://phoenix.craigslist.org/cpg/

What I would like to do is to create an array that looks like this:

Date (as captured by the h4 tag on that page) => in cell [0][0][0],
Link Text => in cell [0][1][0]
Link href => in cell [0][1][1]

i.e. in each row, I store each of those items per row.

What I have done is simply pulled all the h4 tags in and stored them in a hash like this:

contents2[link[:date]] = content_page.css("h4").text

The problem with this is that one cell stores all the text from the h4 tags on the entire page…whereas I would like to have 1 date to 1 cell.

So as an example:

0 => Mon May 28 - Leads need follow up - (Phoenix) - http://phoenix.craigslist.org/wvl/cpg/3043296202.html
1=> Mon May 28 - .Net/Java Developers - (phoenix) - http://phoenix.craigslist.org/cph/cpg/3043067349.html

Any thoughts on how I might approach this, with code would be greatly appreciated.

  • 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-04T23:56:19+00:00Added an answer on June 4, 2026 at 11:56 pm

    How’s this?

    require 'rubygems'
    require 'open-uri'
    require 'nokogiri'
    
    doc = Nokogiri::HTML(open("http://phoenix.craigslist.org/cpg/"))
    
    # Postings start inside the second blockquote on the page
    bq = doc.xpath('//blockquote')[1]
    
    date  = nil         # Temp store of date of postings
    posts = Array.new   # Store array of all postings here
    
    # Loop through all blockquote children collecting data as we go along...
    bq.children.each { |nod|
      # The date is stored in the h4 nodes. Grab it from there.
      date = nod.text if nod.name == "h4"
    
      # Skip nodes until we have a date
      next if !date
    
      # Skip nodes that are not p blocks. The p blocks contain the postings.
      next if nod.name != "p"
    
      # We have a p block. Extract posting data.
      link = nod.css('a').first['href']
      text = nod.text
    
      # Add new posting to array
      posts << [date, text, link]
    }
    
    # Output everything we just collected
    posts.each { |p| puts p.join(" - ") }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to create a web page that for the purposes of this question
Quick question about the Dijit.Form.DateTextBox http://docs.dojocampus.org/dijit/form/DateTextBox This page contains the following: also validates against
This is a very specific question for a Google Chrome extension. http://www.meebo.com/mobile/ This page
I have few question in this regard When you create an internet page, does
Ok, this is pretty weird... Here's the page in question: http://s289116086.onlinehome.us/lawjournaltv/index.php The main blue
The page in question is here: http://supportdogs.digitalportals.net/PhotoGallery/16-Events You can see in IE8 that the
Reference is this page: http://demo.mypreviewbetasite.com/laverona/menu.html File in question: http://demo.mypreviewbetasite.com/laverona/scripts/menu.js The page works as expected
if you look on this page: http://www.lyricsinger.org/lyric/michel-sardou/c-est-ma-vie there are several black diamonds with question
I am learning javascript sample from this page, http://nofunc.org/AJAX_Star_Rating my questions are (1), for
Page in question: http://meyers.ipalaces.org/sitemap/ The first <LI> should be z-index: 2; and should be

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.