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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:37:43+00:00 2026-05-31T08:37:43+00:00

I know there are a tons of docs and debates out there, but still:

  • 0

I know there are a tons of docs and debates out there, but still:

This is my best shot on my Rails attempt to test scraped data from various websites. Strange fact is that if I manually copy-paste the source of an URL everything goes right.

What can I do?

# encoding: utf-8

require 'rubygems'
require 'iconv'
require 'nokogiri'
require 'open-uri'
require 'uri'

url = 'http://www.website.com/url/test'

sio = open(url)
@cur_encoding = sio.charset
doc = Nokogiri::HTML(sio, nil, @cur_encoding)
txtdoc = doc.to_s

# 1) String manipulation test
p doc.search('h1')[0].text # "Nove36  "
p doc.search('h1')[0].text.strip! # nil <- ERROR


# 2) Regex test
# txtdoc = "test test 44.00 € test test" # <- THIS WORKS
regex = "[0-9.]+ €"


p /#{regex}/i =~ txtdoc # integer expected

I realize that probably my OS Ubuntu plus my text editor is doing some good encoding conversion over probably some broken encoding: that’s fine, BUT how can I fix this problem on my app while running live?

  • 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-31T08:37:44+00:00Added an answer on May 31, 2026 at 8:37 am

    The problems you’re having are caused by non breaking space characters (Unicode U+00A0) in the page.

    In your first problem, the string:

    "Nove36  "
    

    actually ends with U+00A0, and String#strip! doesn’t consider this character to be whitespace to be removed:

    1.9.3-p125 :001 > s = "Foo \u00a0"
     => "Foo  " 
    1.9.3-p125 :002 > s.strip
     => "Foo  "    #unchanged
    

    In your second problem, the space between the price and the euro sign is again a non breaking space, so the regex simply doesn’t match as it is looking for a normal space:

    # s as before
    1.9.3-p125 :003 > s =~ /Foo  / #2 spaces, no match
     => nil 
    1.9.3-p125 :004 > s =~ /Foo /  #1 space, match
     => 0 
    1.9.3-p125 :005 > s =~ /Foo \u00a0/  #space and non breaking space, match
     => 0
    

    When you copy and paste the source, the browser probably normalises the non breaking spaces, so you only copy normal space character, which is why it works that way.

    The simplest fix would be to do a global substitution of \u00a0 for space before you start processing:

    sio = open(url)
    @cur_encoding = sio.charset
    
    txt = sio.read             #read the whole file
    txt.gsub! "\u00a0", " "    #global replace
    
    doc = Nokogiri::HTML(txt, nil, @cur_encoding)   #use this new string instead...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there have been tons of answers on this subject, but I still
I know there are tons of threads regarding this issue but I have not
I know there's tons of other threads around about this same topic, but none
So I know there are tons of questions similar to this but I havent
I know that there are tons of questions like this one, but I couldn't
OK, I know there are tons of questions like this, but for some reason
I know that there are tons of articles about this issue. But I'm struggling
I know there are tons of questions about this already floating around SO but
I know there are tons of the same questions, but still OnActivityResult is not
I know there is a lot on this topic but I can't get any

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.