python - Encoding/decoding works in browser, but not in terminal -


here's code:

import urllib  print urllib.urlopen('http://www.indianexpress.com/news/heart-of-the-deal/811626/').read().decode('iso-8859-1') 

when view page in firefox, text displayed correctly. however, on terminal, see issues character encoding.

here malformed output examples:

 long-term  in indias no-go areas 

how can fix this?

try (ignore unknown chars)

import urllib url = 'http://www.indianexpress.com/news/heart-of-the-deal/811626/' print urllib.urlopen(url).read().decode('iso-8859-1').encode('ascii','ignore') 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -