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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:28:02+00:00 2026-05-31T20:28:02+00:00

I have a list of html pages which may contain certain encoded characters. Some

  • 0

I have a list of html pages which may contain certain encoded characters. Some examples are as below –

<a href="mailto:lad%20at%20maestro%20dot%20com">
<em>ada&#x40;graphics.maestro.com</em>
<em>mel&#x40;graphics.maestro.com</em>

I would like to decode (escape, I’m unsure of the current terminology) these strings to –

 <a href="mailto:lad at maestro dot com">
<em>ada@graphics.maestro.com</em>
<em>mel@graphics.maestro.com</em>

Note, the HTML pages are in a string format. Also, I DO NOT want to use any external library like a BeautifulSoup or lxml, only native python libraries are ok.

Edit –

The below solution isn’t perfect. HTML Parser unescaping with urllib2 throws a

UnicodeDecodeError: 'ascii' codec can't decode byte 0x94 in position 31: ordinal not in range(128)

error in some cases.

  • 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-31T20:28:04+00:00Added an answer on May 31, 2026 at 8:28 pm

    You need to unescape HTML entities, and URL-unquote.
    The standard library has HTMLParser and urllib2 to help with those tasks.

    import HTMLParser, urllib2
    
    markup = '''<a href="mailto:lad%20at%20maestro%20dot%20com">
    <em>ada&#x40;graphics.maestro.com</em>
    <em>mel&#x40;graphics.maestro.com</em>'''
    
    result = HTMLParser.HTMLParser().unescape(urllib2.unquote(markup))
    for line in result.split("\n"): 
        print(line)
    

    Result:

    <a href="mailto:lad at maestro dot com">
    <em>ada@graphics.maestro.com</em>
    <em>mel@graphics.maestro.com</em>
    

    Edit:
    If your pages can contain non-ASCII characters, you’ll need to take care to decode on input and encode on output.
    The sample file you uploaded has charset set to cp-1252, so let’s try decoding from that to Unicode:

    import codecs 
    with codecs.open(filename, encoding="cp1252") as fin:
        decoded = fin.read()
    result = HTMLParser.HTMLParser().unescape(urllib2.unquote(decoded))
    with codecs.open('/output/file.html', 'w', encoding='cp1252') as fou:
        fou.write(result)
    

    Edit2:
    If you don’t care about the non-ASCII characters you can simplify a bit:

    with open(filename) as fin:
        decoded = fin.read().decode('ascii','ignore')
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a list of links which point to html pages. <ul id="item-list"> <li><a
I have a html form which have a select list box from which you
I have a web form which is split up into several HTML pages. I
I have created a list in jquery mobile which directs to some page on
I have an HTML list ( <ul> , <li> , etc.) of pages, with
I am working on an iPhone application in which I have HTML pages created
In our HTML page, we have a list of tags to load in many
I have a simple html form. On php page. A simple list is placed
I have multiple dropdown list: @Html.DropDownListFor(x => x.HaveColoSpace.SelectedOptions, new SelectList(Model.HaveColoSpace.Options, Value, Text), new {
I have an ordered list in HTML. I would like to add styling only

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.