嘿,我正在使用beautifulsoup(在scrapy的两天挣扎未果之后)来刮掉星际2的联赛数据,但是我遇到了一个问题。使用python中的beautifulsoup的输出
我有这个表,而我想,我不喜欢这样所有标签的字符串内容结果:
from BeautifulSoup import *
from urllib import urlopen
def parseWithSoup(url):
print "Reading:" , url
html = urlopen(url).read().lower()
bs = BeautifulSoup(html)
table = bs.find(lambda tag: tag.name=='table' and tag.has_key('id') and tag['id']=="tblt_table")
rows = table.findAll(lambda tag: tag.name=='tr')
rows.pop(0) #first row is header
for row in rows:
tags = row.findAll(lambda tag: tag.name=='a')
content = []
for tagcontent in tags:
content.append(tagcontent.string)
print content
if __name__ == '__main__':
content = "http://www.teamliquid.net/tlpd/sc2-international/games#tblt-5018-1-1-DESC"
metSoup = parseWithSoup(content)
但输出如下:
[u'+', u'gadget show live i..', u'crevasse', u'naniwa', u'socke']
[u'+', u'gadget show live i..', u'metalopolis 1.1', u'naniwa', u'socke']
[u'+', u'gadget show live i..', u'shakuras plateau 2.0', u'socke', u'select']
etc...
我的问题是:你来自哪里(来自unicode?),我该如何删除它?我只需要在u中的字符串...
>>> l = [u'+',u'gadget show live i ..',u'crevasse',u'naniwa',u'socke'] >>> l [1] u'小工具秀现场直播......'。 >>> print l [1] #still unicode but you with print no 012 gadget show live我.. – snippsat 2011-04-17 15:36:03