문제

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

도움이 되었습니까?

해결책

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

Accept: text/plain

if you like this :)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top