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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:21:36+00:00 2026-06-17T14:21:36+00:00

This is my code: doc= Nokogiri::HTML(open(http://www.cincinnatisun.com/index.php?rss/90d24f4ad98a2793, ‘User-Agent’ => ‘ruby’)) search=doc.css(‘item’) if !search.blank? search.each do

  • 0

This is my code:

doc= Nokogiri::HTML(open("http://www.cincinnatisun.com/index.php?rss/90d24f4ad98a2793", 'User-Agent' => 'ruby'))
search=doc.css('item')
if !search.blank?
  search.each do |data|
    title=data.css("title").text

    link=data.css("link").text
  end
end

but I did not get the link.

  • 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-17T14:21:38+00:00Added an answer on June 17, 2026 at 2:21 pm

    Several things are wrong:

    if !search.blank?
    

    won’t work because search would be a NodeSet returned by doc.css. NodeSet‘s don’t have a blank? method. Perhaps you meant empty??

    title=data.css("title").text
    

    isn’t the correct way to find the title because, like in the above problem, you’re getting a NodeSet instead of a Node. Getting text from a NodeSet can return a lot of garbage you don’t want. Instead do:

    title=data.at("title").text
    

    Changing the code to this:

    require 'nokogiri'
    require 'open-uri'
    
    doc= Nokogiri::HTML(open("http://www.cincinnatisun.com/index.php?rss/90d24f4ad98a2793", 'User-Agent' => 'ruby'))
    search=doc.css('item')
    if !search.empty?
      search.each do |data|
        title=data.at("title").text
        link=data.at("link").text
        puts "title: #{ title } link: #{ link }"
      end
    end
    

    Outputs:

    title: Ex-Bengals cheerleaders lawsuit trial to begin link:
    title: Freedom Center Offering Free Admission Monday link:
    title: Miami University Band Performing in the Inaugural Parade link:
    title: Northern Kentucky Man To Present Colors At Inauguration link:
    title: John Gumms Monday Forecast link:
    title: President Obama VP Biden sworn in officially begin second terms link:
    title: Colerain Township Pizza Hut Robbed Saturday Night link:
    title: Cold Snap Coming to Tri-State link:
    title: 2 Men Arrested After Police Chase in Northern Kentucky link:
    

    The link won’t work because the XML is malformed, which, in my experience, is unbelievably common on the internet because people don’t take the time to check their work.

    The fix is going to take massaging the XML prior to Nokogiri receiving the content, or to modify your accessors. Luckily, this particular XML is easy to work around so this should help:

    require 'nokogiri'
    require 'open-uri'
    
    doc = Nokogiri::HTML(open("http://www.cincinnatisun.com/index.php?rss/90d24f4ad98a2793", 'User-Agent' => 'ruby'))
    search = doc.css('item')
    if !search.empty?
      search.each do |data|
        title = data.at("title").text
        link = data.at("link").next_sibling.text
        puts "title: #{ title } link: #{ link }"
      end
    end
    

    Which outputs:

    title: Ex-Bengals cheerleaders lawsuit trial to begin link: http://www.cincinnatisun.com/index.php/sid/212072454/scat/90d24f4ad98a2793
    title: Freedom Center Offering Free Admission Monday link: http://www.cincinnatisun.com/index.php/sid/212072914/scat/90d24f4ad98a2793
    title: Miami University Band Performing in the Inaugural Parade link: http://www.cincinnatisun.com/index.php/sid/212072915/scat/90d24f4ad98a2793
    title: Northern Kentucky Man To Present Colors At Inauguration link: http://www.cincinnatisun.com/index.php/sid/212072913/scat/90d24f4ad98a2793
    title: John Gumms Monday Forecast link: http://www.cincinnatisun.com/index.php/sid/212070535/scat/90d24f4ad98a2793
    title: President Obama VP Biden sworn in officially begin second terms link: http://www.cincinnatisun.com/index.php/sid/212060033/scat/90d24f4ad98a2793
    title: Colerain Township Pizza Hut Robbed Saturday Night link: http://www.cincinnatisun.com/index.php/sid/212057132/scat/90d24f4ad98a2793
    title: Cold Snap Coming to Tri-State link: http://www.cincinnatisun.com/index.php/sid/212057131/scat/90d24f4ad98a2793
    title: 2 Men Arrested After Police Chase in Northern Kentucky link: http://www.cincinnatisun.com/index.php/sid/212057130/scat/90d24f4ad98a2793
    

    All that done, you can write your code more clearly like:

    require 'nokogiri'
    require 'open-uri'
    
    doc = Nokogiri::HTML(open("http://www.cincinnatisun.com/index.php?rss/90d24f4ad98a2793", 'User-Agent' => 'ruby'))
    doc.css('item').each do |data|
      title = data.at("title").text
      link = data.at("link").next_sibling.text
      puts "title: #{ title } link: #{ link }"
    end
    

    Interestingly enough, now the sample page appears to have its links fixed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code snippet taken from http://doc.qt.digia.com/qt/qhboxlayout.html#details is, barring some magic I'm not aware of,
So I have code that looks like this: content_url = 'http://auburn.craigslist.org/cpg/index.rss' doc = Nokogiri::XML(open(content_url))
I all, I just follow this great example: http://qt-project.org/doc/qt-4.8/tools-customcompleter.html I copy the code exactly
I'm trying to parse a html doc using some code I found from this
This Ruby code using Nokogiri doc.xpath(//tbody).remove removes the children of the <tbody> (as well
Apparently Nokogiri's add_class method only works on NodeList s, making this code invalid: doc.search('a').each
I'm parsing an HTML document using Nokogiri. The code contain several images like this:
Given this XML ... <ListBucketResult xmlns=http://s3.amazonaws.com/doc/2006-03-01/> <Name>public.rpmware.com</Name> <Prefix></Prefix> <Marker></Marker> <MaxKeys>1000</MaxKeys> <IsTruncated>false</IsTruncated> <Contents> <Key>0.dir</Key> <LastModified>2008-06-25T16:09:49.000Z</LastModified>
I am using this plugin http://almende.github.com/chap-links-library/js/timeline/doc/ to render a timeline from some JSON data.
i have this code in c# doc.SelectSingleNode(WhoisRecord/registrant/email).InnerText how can i check whether it is

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.