Question

i am using python urllib2.urlopen to get html content and i am getting a gziped response.
can i set the headers so i will get it not zipped ?

my code

response = urlopen(url,None , TIMEOUT)
html = response.read()  # read html
print html

as Tichodroma suggested i try this

request = Request(url)
request.add_header('Accept-encoding', 'text/plain')
response = urlopen(request,None , TIMEOUT)
html = response.read().lower()  # read html
print html

now it is working

Was it helpful?

Solution

Set the Accept header to the mime types you want to accept.

Accept: text/plain

if you like this :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top