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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:22:32+00:00 2026-05-27T19:22:32+00:00

Given a page like What popular startup advice is plain wrong? , I’d like

  • 0

Given a page like “What popular startup advice is plain wrong?“, I’d like to be able to extract the first topic under the topic heading on the upper right hand side, in this case, “Common Misconceptions”.

What’s the best way for me to do this in Ruby? Is it with Nokogiri or a regex? Presumably I need to do some HTML parsing?

  • 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-05-27T19:22:32+00:00Added an answer on May 27, 2026 at 7:22 pm

    First, you almost never, ever, want to use regular expressions to parse/extract/fold/spindle/mutilate XML or HTML. There are too many ways it can go wrong. Regular expressions are great for some jobs, but XML/HTML extractions are not a good fit.

    That said, here’s what I’d do using Nokogiri:

    require 'nokogiri'
    require 'open-uri'
    
    doc = Nokogiri::HTML(open('http://www.quora.com/What-popular-startup-advice-is-plain-wrong'))
    
    topic = doc.at('span a.topic_name span').content
    puts topic
    

    Running that outputs:

    Common Misconceptions
    

    The code is taking a couple shortcuts, that should work consistently:

    1. Using Ruby’s OpenURI allows easy accessing of Internet resources. It’s my go-to for most simple to average apps. There are more powerful tools but none as convenient.
    2. doc.at tells Nokogiri to traverse the document, and find the first occurrence of the CSS accessor ‘span a.topic_name span‘, which should be consistent in that page as the first entry.

    Note that Nokogiri supports some variants of searching for a node: at vs. search. at and % and things like css_at find the first occurrence and return a Node, which is an individual tag or text or comment. search, /, and those variants return a NodeSet which is like an array of Nodes. You’ll have to walk that list or extract the individual nodes you want using some sort of Array accessor. In the above code I could have said doc.search(...).first to get the node I wanted.

    Nokogiri also supports using XPath accessors, but for most things I’ll usually go with CSS. It’s simpler, and easier to read, but your mileage might vary.

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

Sidebar

Related Questions

Given an HTML page I would like to get all the 'x' files that
I know how to get the number of people who like a given page,
Given that I have a JavaScript section in my HTML page like : <script
I am given a page url like 'http://abc.com/test.php?a=1&b=2&c=3' . Now I have been told
I would like to detect when a page load request give to a UIWebView
Given remote page: http://example.com/paged_list.aspx which uses a Javascript function call to display several pages
Given an HTML page that has a complex table-based layout and many tags that
Given this class public partial class Default : Page { private IRepository repo; ...
My clients home page is https://www.quakereadykit.com/store/home.php This was given to me by a previous
Given hello.php: <?php echo Hello; ?> rendering the page works fine and returns Hello

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.