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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:36:51+00:00 2026-05-31T23:36:51+00:00

Hello here is my script: ARGV.each do |input_filename| doc = Nokogiri::HTML(File.read(input_filename)) title, body =

  • 0

Hello here is my script:

ARGV.each do |input_filename|
  doc = Nokogiri::HTML(File.read(input_filename))
  title, body = doc.title.gsub("/\s+/"," ").downcase.strip, doc.xpath('//body').inner_text.tr('"', '').gsub("\n", '').downcase.strip
  link = doc.search("a[@href]") //Adding this part generates errors
  filename = File.basename(input_filename, ".*")
  puts %Q("#{title}", "#{body}", "#{filename}", "#{link}").downcase
end

I am having trouble extracting links from a list of html files. I believe the issue is due to unconventional coding in some of the html files. Here is the error i am getting.

extractor.rb:9:in `block in <main>': incompatible character encodings: UTF-8 and  CP850 (Encoding::CompatibilityError)
        from extractor.rb:4:in `each'
        from extractor.rb:4:in `<main>'
  • 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-31T23:36:52+00:00Added an answer on May 31, 2026 at 11:36 pm

    Nokogiri stores Strings always as UTF-8 internally. Methods that return text values will always return UTF-8 encoded strings.

    You have a conflict UTF-8 and cp850 (you are working with windows?).
    You may adapt your File.read(input_filename)

    Try

    File.read(input_filename, :encoding => 'cp850:utf-8') 
    

    If your html-files are windows files.

    If your html-files are already utf-8, the try:

    File.read(input_filename, :encoding => 'utf-8') 
    

    Another solution may be a Encoding.default_external = 'utf-8' at the begin of your code. (I wouldn’t recommend it, use it only for small scripts).

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

Sidebar

Related Questions

I have the following: <html> <body> <script type="text/javascript"> document.write('Hello\nWorld') </script> </body> </html> As you
Hello friends here's my code function dropItems(idOfDraggedItem,targetId,x,y) { var html = document.getElementById('dropContent').innerHTML; if(html.length<=0){ html.innerHTML='<img
Here is google's hello world code for v3: http://code.google.com/apis/maps/documentation/javascript/tutorial.html#HelloWorld this loads and displays the
Hello there i got some code here; <script type=text/javascript> $(function(){ var playListURL = 'http://gdata.youtube.com/feeds/api/playlists/8BCDD04DE8F771B2?v=2&alt=json&callback=?';
Hello o have an html form and a php script and html passes some
Here is a simple page: <!DOCTYPE HTML> <html lang=en> <head> <meta charset=UTF-8> <title>Test page</title>
hello im am getting JS error : Uncaught SyntaxError: Unexpected identifier here <script type=text/javascript>
Here's my script: read -p 'commit message: ' msg svn status | grep ^\?
CODE HERE: http://jsfiddle.net/B7Y43/ Hello fello programmers, I have the following situation: My PHP-script generates
Here's my script: #!/usr/bin/python import smtplib msg = 'Hello world.' server = smtplib.SMTP('smtp.gmail.com',587) #port

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.