[英]I am trying to get html data from a site using urllib but for some sites i am ending up with some unknown characters in python
Hey guys i am trying to get a html data from a site using urllib.openurl.read() but for some sites all i am getting is data link this * 6\\xbdW\\xb6\\xd6\\xff\\xca\\x9d\\x9bO|\\xc0\\x96a\\xc7\\xc8\\xf7\\xa7\\x10-\\x8aM{\\xf8\\x* and i have no clue what it is and why i am getting like this. 嘿家伙我试图从网站使用urllib.openurl.read()获取html数据,但对于一些网站,我得到的是数据链接* 6 \\ xbdW \\ xb6 \\ xd6 \\ xff \\ xca \\ x9d \\ x9bO | \\ xc0 \\ x96a \\ xc7 \\ xc8 \\ xf7 \\ xa7 \\ x10- \\ x8aM {\\ xf8 \\ x *并且我不知道它是什么以及为什么我会这样。 I tried googling it some said there is encoding decoding problem i tried that as well but as you can see no luck there so please guide me in this darkness.
我试着谷歌搜索一些说有编码解码问题我试过,但你可以看到没有运气那么请指导我在这黑暗中。 Here is my code --- >
这是我的代码--->
url = "http://mangafox.me/manga/online_the_comic/c001/1.html" # for this site and some more its not working
page = urllib.urlopen(url).read()
print page
and you guys know whats happening after printing this code. 你知道打印这段代码后发生了什么。
This page its on gzip format, you got to unzip before take the data: 这个页面是gzip格式的,你需要在获取数据之前解压缩:
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8b in position 1: ordinal not in range(128)
0x8b in the begin of the code it means gzip format. 代码开头的0x8b表示gzip格式。
You should take a look in this question: 你应该看看这个问题:
twitter trends api UnicodeDecodeError: 'utf8' codec can't decode byte 0x8b in position 1: unexpected code byte twitter trend api UnicodeDecodeError:'utf8'编解码器无法解码位置1的字节0x8b:意外的代码字节
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.