如何在python中编写html和特殊字符?

2024-04-25 22:27:59 发布

您现在位置:Python中文网/ 问答频道 /正文

1543159687.4969957::I think I\u2019ve gotten far enough into my experiment to give an update: Last year, Child of Humanity was free for Blac\u2026 https://t.co/M3HR5fAoFZ"

这是我得到的结果。我想创建一个正则表达式,用空格替换\u2019和\u2026这样的特殊元素。它们总是以“\u”开头,然后继续四个字符。你知道吗

我也想摆脱html。总是以“开始”https://t.co/“并持续10个字符。你知道吗

我试过下面的代码,但显然是错的。你知道吗

tweet = re.sub("@[\\u].{4}", "", tweet)

Tags: tohttpsanmytweetexperimentfarco
1条回答
网友
1楼 · 发布于 2024-04-25 22:27:59

那些\u字符只是unicode字符,您不需要做任何事情,因为当您尝试print mystring时,它们将自动转换

至于最终的url,您可以:

removed = re.sub(r'http\S*$', '', mystring) # remove the final http string.

>>> removed
'1543159687.4969957::I think I’ve gotten far enough into my experiment to give an update: Last year, Child of Humanity was free for Blac… '

相关问题 更多 >