在ubuntu下使用python,目标是用beautifulsoup抓取百度贴吧的一个链接,获取它的title然后打印出来。现在的问题是百度的编码是gbk,我用如下代码:
c = urllib2.urlopen('http://tieba.baidu.com/p/2163299007')
soup = BeautifulSoup(c.read)
title = soup('title')[0].string
str = title.decode('gbk').encode('utf-8')
print str
结果输出的还是乱码,大家有什么想法么。。
c = urllib2.urlopen('http://tieba.baidu.com/p/2163299007')
soup = BeautifulSoup(c.read)
title = soup('title')[0].string
str = title.decode('gbk').encode('utf-8')
print str
结果输出的还是乱码,大家有什么想法么。。