Get document as normal text and not as binary data
Fredrik Lundh
fredrik at pythonware.com
Sun Mar 27 07:35:10 EST 2005
Markus Franz wrote:
> I used urllib2 to load a html-document through http. But my problem
> is: The loaded contents are returned as binary data, that means that every
> character is displayed like lÃ?Ãt, for example. How can I get the
> contents as normal text?
>
> My script was:
>
> import urllib2
> req = urllib2.Request(url)
> f = urllib2.urlopen(req)
adding
print f.headers
and checking the header fields (especially the content-type) may help you
figure out what's going on...
> contents = f.read()
> print contents
> f.close()
</F>
More information about the Python-list
mailing list