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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:32:43+00:00 2026-06-02T12:32:43+00:00

I am using python2.7 and lxml. My code is as below import urllib from

  • 0

I am using python2.7 and lxml. My code is as below

import urllib
from lxml import html

def get_value(el):
    return get_text(el, 'value') or el.text_content()

response = urllib.urlopen('http://www.edmunds.com/dealerships/Texas/Frisco/DavidMcDavidHondaofFrisco/fullsales-504210667.html').read()
dom = html.fromstring(response)

try:
    description = get_value(dom.xpath("//div[@class='description item vcard']")[0].xpath(".//p[@class='sales-review-paragraph loose-spacing']")[0])
except IndexError, e:
    description = ''

The code crashes inside the try, giving an error

UnicodeDecodeError at /
'utf8' codec can't decode byte 0x92 in position 85: invalid start byte

The string that could not be encoded/decoded was: ouldn�t be

I have tried using a lot of techniques including .encode(‘utf8’), but none does solve the problem. I have 2 question:

  1. How to solve this problem
  2. How can my app crash when the problem code is between a try except
  • 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-06-02T12:32:44+00:00Added an answer on June 2, 2026 at 12:32 pm

    The page is being served up with charset=ISO-8859-1. Decode from that to unicode.

    [Snapshot of details from a browser. Credit @Old Panda]

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

Sidebar

Related Questions

Question How do I remove class attributes from html using python and lxml? Example
I am using python lxml library to parse html pages: import lxml.html # this
I am using lxml to scrape html. This code works. lxml.html.parse( http://google.com/ ) This
Using Python2.4 I want to capture output from a mysql command. One caveat is
I am using Python & lxml and am stuck with an error My code
I would like to parse an HTML document using lxml. I am using python
Using lxml in python I created this xpath syntax htmlPage.xpath(/html/body//a/text()) It gets me all
I'm using lxml in Python to parse some HTML and I want to extract
Please help me parse a configuration file of the below prototype using lxml etree.
I am using lxml to convert html into txt. I almost get to where

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.