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
Post a Comment