我使用正则表达式来解析网站的源代码,并在Tkinter
窗口中显示新闻标题。有人告诉我用regex解析HTML不是最好的主意,但不幸的是现在没有时间去改变。在
我似乎无法为诸如撇号('
)等特殊字符替换HTML代码。在
目前我有以下情况:
union_url = 'http://www.news.com.au/sport/rugby'
def union():
union_string = urlopen(union_url).read()
union_string.replace("’", "'")
union_headline = re.findall('(?:sport/rugby/.*) >(.*)<', union_string)
union_headline_label= Label(union_window, text = union_headline[0], font=('Times',20,'bold'), bg = 'White', width = 85, height = 3, wraplength = 500)
这并不能消除HTML字符。例如,标题打印为
^{pr2}$我试图找到一个答案,但没有任何运气。任何帮助都是非常感谢的。在
您可以使用的“可调用”功能re.sub公司()清除(或删除)任何逃逸的东西:
相关问题 更多 >
编程相关推荐