Python:如何从给定文本中解析Tiktok URL
您好,我试图解析文本并提取
text = "This is a text https://www.tiktok.com/@tt_user/video/7620173214578963251 and more text"
通常在python中的tiktok URL,以解析URL,我使用以下言论:
import re
url = re.search("(?P<url>https?://[^\s]+)", text).group("url")
但是此方法对于tiktok而言失败(我假设它是用于“@@in@in@in” URL
AttributeError: 'NoneType' object has no attribute 'group'
我想知道如何使用以下条件或(2)使用另一种方法正确提取我的tiktok
Hello I am trying to parse a text and extract the Tiktok Url that it is in it
text = "This is a text https://www.tiktok.com/@tt_user/video/7620173214578963251 and more text"
Normally in python, to parse an url, I use the following regex:
import re
url = re.search("(?P<url>https?://[^\s]+)", text).group("url")
But this method fails for tiktok (i assume it is for the "@" in the url)
AttributeError: 'NoneType' object has no attribute 'group'
I would like to know how to extract my tiktok urls properly by (1) using a regex or (2) Using another method
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要逃脱'\'/'
You need to escape '\' the '/'