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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:32:46+00:00 2026-05-28T15:32:46+00:00

I’m trying BeautifulSoup for parsing html files which is encoded in UTF-8. But unfortunately,

  • 0

I’m trying BeautifulSoup for parsing html files which is encoded in UTF-8. But unfortunately, this html file contains a few characters which are non-utf-8 character, hence not showed correctly. But this is OK for me since I could just simply skip these characters.

The problems is, even if I directly specify the encodingFrom as utf-8:

soup = BeautifulSoup (html,fromEncoding='utf-8')

It turns out the soup.originalEncoding is set to default windows-1252 automatically.

print soup.originalEncoding
windows-1252

I referred to the BeautifulSoup Documents and it’s written like:

Beautiful Soup tries the following encodings, in order of priority, to turn your document into Unicode:

 - An encoding you pass in as the fromEncoding argument to the soup
   constructor.
 - An encoding discovered in the document itself
 - An encoding sniffed by looking at the first few bytes of the file. If
   an encoding is detected at this stage, it will be one of the UTF-*
   encodings, EBCDIC, or ASCII.
 - An encoding sniffed by the chardet library, if you have it installed.
 - UTF-8
 - Windows-1252

It seems it should use fromEncoding I specified instead of falling to the last one in the list.

Here is the original html I’m parsing for your reference.

  • 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-28T15:32:47+00:00Added an answer on May 28, 2026 at 3:32 pm

    If you know what the encoding of file will be, try decoding your string before passing it to BeautifulSoup and explicitly ignore non-utf8 characters.

    unicode_html = myfile.read().decode('utf-8', 'ignore')
    soup = BeautifulSoup (unicode_html)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
This could be a duplicate question, but I have no idea what search terms
I'm trying to select an H1 element which is the second-child in its group
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.