Python论坛  - 讨论区

标题:[python-chinese] 使用httplib模块获取中文页面后,把中文打印出来为乱码问

2007年03月25日 星期日 01:29

alex yu yu.alex.z.y在gmail.com
星期日 三月 25 01:29:14 HKT 2007

ÎÒÒ²ºÜÏëÖªµÀÔõôʹÓÃhttplib£¿

ÓÐûÓÐÃèÊöhttplibÕâ¸ö¿âÈçºÎʹÓõÄÎĵµ°¢£¿

лл´ó¼ÒÁË


On 1/23/07, ¿¡½Ü²Ì <yzcaijunjie在gmail.com> wrote:
>
> if __name__ == "__main__":
>     print "¿ªÊ¼......"
>     conn = httplib.HTTPConnection('www.baidu.com')
>     conn.request("GET","/index.html")
>     response = conn.getresponse()
>     html=response.read()
>     conn.close()
>     print html
>
> ´òÓ¡html£¬ÀïÃæÖÐÎÄÏÔʾΪÂÒÂë¡£ÎÒÒ²³¢ÊÔ¹ýʹÓÃ
> html=response.read().encode('gbk')
> ½á¹û£¬ÔËÐÐʱ´íÎó
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position 124:
> ordinal not in range(128)
>
> ÇëÎÊÕâÊÇʲôԭÒòÄØ£¿
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070325/9c048516/attachment-0001.html 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2007年03月26日 星期一 15:59

wentrue guozhuwen在gmail.com
星期一 三月 26 15:59:45 HKT 2007

ÏÈdecode£¬ÔÙencode£¿

ÔÚ07-3-25£¬alex yu <yu.alex.z.y在gmail.com> дµÀ£º
>
> ÎÒÒ²ºÜÏëÖªµÀÔõôʹÓÃhttplib£¿
>
> ÓÐûÓÐÃèÊöhttplibÕâ¸ö¿âÈçºÎʹÓõÄÎĵµ°¢£¿
>
> лл´ó¼ÒÁË
>
>
> On 1/23/07, ¿¡½Ü²Ì <yzcaijunjie在gmail.com> wrote:
> >
> > if __name__ == "__main__":
> >     print "¿ªÊ¼......"
> >     conn = httplib.HTTPConnection('www.baidu.com')
> >     conn.request("GET","/index.html")
> >     response = conn.getresponse()
> >     html=response.read()
> >     conn.close()
> >     print html
> >
> > ´òÓ¡html£¬ÀïÃæÖÐÎÄÏÔʾΪÂÒÂë¡£ÎÒÒ²³¢ÊÔ¹ýʹÓÃ
> > html=response.read().encode('gbk')
> > ½á¹û£¬ÔËÐÐʱ´íÎó
> > UnicodeDecodeError: 'ascii' codec can't decode byte 0xb0 in position
> > 124: ordinal not in range(128)
> >
> > ÇëÎÊÕâÊÇʲôԭÒòÄØ£¿
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to
> > python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20070326/351a77a2/attachment.htm 

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号