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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T06:48:06+00:00 2026-05-31T06:48:06+00:00

I am very new to Ruby and I am currently working on site-scraping using

  • 0

I am very new to Ruby and I am currently working on site-scraping using Nokogiri to practice. I would like to scrape the details from ‘deals’ from a random group-buying site. I have been able to successfully scrape a site but I am having problems in parsing the output. I tried the solutions suggested in here and also using regex. So far, I have failed.

I am trying to parse the following title/description from this page:

Frosty Frappes starting at P100 for P200 worth at Café Tavolo – up to 55% off

This is what I got:

FrostyFrappes starting at P100 for P200 worth at Caf Tavolo  up to 55% off

Here are the snippets in my code:

require 'uri'
require 'nokogiri'

html = open(url)
doc = Nokogiri::HTML(html.read)
doc.encoding = "utf-8"
title = doc.at_xpath('/html/body/div/div[9]/div[2]/div/div/div/h1/a')
puts title.content.to_s.strip.gsub(/[^0-9a-z%&!\n\/(). ]/i, '')

Please do tell me if I missed something out. Thank you.

  • 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-31T06:48:08+00:00Added an answer on May 31, 2026 at 6:48 am

    Your xpath is too rigid and your regex is removing chars you want to keep. Here’s how I would do it:

    title = doc.at('div#contentDealTitle h1 a').text.strip.gsub(/\s+/,' ')
    

    That says take the text from the first a tag that comes after div#contentDealTitle and h1, strip it (remove leading and trailing spaces) and replace all sequences of 1 or more whitespace char with a single space.

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

Sidebar

Related Questions

I am very new to Ruby so could you please suggest the best practice
I have built a very simple blog application using Ruby on Rails. New to
I am very new to Ruby (2-3 days) and am using it on an
I'm very new to Ruby, and currently running through the Ruby Koans to get
I am still very new to Ruby (reading through the Pickaxe and spending most
I'm very new to Ruby on Rails so please go easy! I've uploaded the
I'm very new to ruby. I'm trying to search for any instance of a
Very new to using Raphael.js I'm looking at the tutorials and I am able
I am very new to Ruby and Rails. I use rails 3.0.9 and ruby
To begin, I am very new to Ruby on Rails. So I want to

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.