这是我的脚本蟒蛇UTF-8的问题
# -*- coding: utf-8 -*-
from BeautifulSoup import BeautifulSoup
import urllib2
res = urllib2.urlopen('http://tazeh.net')
html = res.read()
soup = BeautifulSoup(''.join(html))
title = soup.findAll('title')
print title
时,即时通讯正在运行在终端这个剧本我得到委屈一样,
$ python test.py
[<title>ŮžŘ§ŰŒÚŻŘ§Ů‡ ŘŽŘ¨ŘąŰŒ ŘŞŘŮ„ŰŒŮ„ŰŒ تازه</title>]
这个标题文本在UTF-8编码和波斯语
我是新来的python有什么不对吗?
你有没有尝试过title.decode()? – Daniel
将脚本底部改为'code' title = soup.findAll('title') title = title [0] .string.decode('utf-8') print title'code' got error return codecs.utf_8_decode(输入,错误,True) UnicodeEncodeError:'ascii'编解码器无法编码位置0-4的字符:序号不在范围内(128) –
您的问题解决了吗? :D – Efazati