Python urllib2解析html问题 [英] Python urllib2 parse html problem

查看:190
本文介绍了Python urllib2解析html问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用机械化方法来解析网站的html,但是使用此网站,我得到了奇怪的结果.

I am using mechanize to parse html of website, but with this website i got strange result.

from mechanize import Browser
br = Browser()
r = br.open("http://www.heavenplaza.com")
result = r.read()

结果是我无法理解的东西.您可以在此处看到: http://paste2.org/p/1556077

result is something which i can not understand. you can see here: http://paste2.org/p/1556077

任何人都可以通过某种方法获取该网站的HTML?机械化或urllib.

Anyone can have some method to get that website HTML? with mechanize or urllib.

谢谢

推荐答案

import urllib2, StringIO, gzip
f = urllib2.urlopen("http://www.heavenplaza.com")
data = StringIO.StringIO(f.read())
gzipper = gzip.GzipFile(fileobj=data)
print gzipper.read()

这篇关于Python urllib2解析html问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆