2016-10-08 35 views
0

您好我正在运行python正则表达式从新闻页面提取一些数据,但是当它显示时代码会在输出中生成括号和撇号。例如,这是我的代码:从新闻页面提取数据的正则表达式

description_title = findall('<item>[\s]*<title[^>]*>(.*?)<\/title>[\s]*<description>', html_source)[:1] 
     news_file.write('<h3 align="Center">' + str(description_title) + ": " + '</h3\n>') 

但是这个代码创建[“技术”] :, [“财经”]的输出:但我想科技,金融,而不[“”]周围。

+0

http://stackoverflow.com/questions/11178061/print-list-without-brackets-in-a-single-row –

回答

1

通过使用str,您打印的Python字符串表示形式为description_title(这是长度为1的list)。尽量不str

'<h3 align="Center">' + description_title[0] + ": " + '</h3\n>' 
+3

的可能重复。如果事实上,'str'不在这种特殊的情况下,它称之为“repr”。它返回Python列表的字符串表示。 –