gpt4 book ai didi

python - 如何在Python中编码掉html和特殊字符?

转载 作者:太空宇宙 更新时间:2023-11-03 21:31:55 25 4
gpt4 key购买 nike

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)

最佳答案

那些\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… '

关于python - 如何在Python中编码掉html和特殊字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53469098/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com