python - output html in terminal error -
After
I am trying to print html content in the following manner:
import lxml HTML import request URL from '= http://www.amazon.co.uk/Membrane-Protectors-FujiFilm-FinePix-SL1000/dp/B00D2UVI9C/ref=pd_sim_ph_3?ie=UTF8&refRID=06BDVRBE6TT4DNRFWFVQ' page = requests.get (Url) print page.text
then I execute python print_url.py & gt;
, and I found the following error:
print UnicodeEncodeError page.text: 'ascii' codec character can not be encode in the '\ xa3' position 113,525: No Sortable range in (128)
Can someone give me some ideas? I had this problem first, but I could not understand it. Thank you
Your page.txt
is not in your local encoding. Instead it's probably Unicode to print the contents of the page.text you expect the first encoding that encode them into stdout:
import sys print page.text.encode (Sys.stdout.encoding)
Comments
Post a Comment