正则表达式从新闻页面提取数据

时间:2016-10-08 13:16:57

标签: python html regex

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

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

但是这段代码创造了[&#39;技术&#39;]:,[&#39;财务&#39;]的输出:但我想要技术,财务而没有[&#39;&#39; ] 周围。

1 个答案:

答案 0 :(得分:1)

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

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