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

  • Home
  • SEARCH
  • 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 7769681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:13:06+00:00 2026-06-01T16:13:06+00:00

Learning scraping with Ruby. I’m trying to count the amount of outbound links a

  • 0

Learning scraping with Ruby. I’m trying to count the amount of outbound links a given page has, but I’m not sure how to tell Ruby I only want the outbound links counted.

My current code:

require "open-uri"

# Collect info
puts "What is your URL?"
url = gets.chomp
puts "Your URL is #{url}"
puts "Loading..."

# Check keyword count
page = open(url).read
link_total = page.scan("</a>")
# obl_count = ???
link_count = link_total.count
puts "Your site has a total of #{link_count} links."

How can I complete this?

  • 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-01T16:13:08+00:00Added an answer on June 1, 2026 at 4:13 pm

    Just as you should never parse HTML with regular expressions, you should probably be using nokogiri to do the dirty work for you.

    In simple terms you can use CSS selectors to find tags. From there it’s easy to count:

    Nokogiri::HTML(page).css('a').length
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Learning C at University. This is not a homework, but I was trying to
Learning Ruby. Needed to create a hash of arrays. This works... but I don't
Learning CasperJS Trying to understand why the following is not displaying my results in
Learning how to do a master page in asp.net. Trying to figure out how
I am learning scraping using the PHP Simple HTML DOM Parser and Xpath. Accroding
Learning java server technologies, trying to clarify some things. There are few technologies that
Learning to use Ruby Threads for transportability of code between different OS platforms. The
I'm learning to use the fantastic enlive library to do some web-scraping. I need
I have been here for a couple of months learning python from examples, but
Learning about Explicit Cursors and trying to create my frst one.: SET SERVEROUTPUT ON

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.