【发布时间】:2019-03-30 12:24:21
【问题描述】:
我要检查数千个字符串,我需要获取包含instagram.com/p/的完整url
到目前为止,我都在使用这种方法:
msg ='hello there http://instagram.com/p/BvluRHRhN16/'
msg = re.findall(
'http[s]?://?[\w/\-?=%.]+instagram.com/p/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+',
msg)
print(msg)
但有些网址找不到。
我想获取所有类似以下的网址:
https://instagram.com/p/BvluRHRhN16/
https://www.instagram.com/p/BvluRHRhN16/
http://instagram.com/p/BvluRHRhN16/
https://www.instagram.com/p/BvluRHRhN16/
www.instagram.com/p/BvluRHRhN16/
我怎样才能以最快的方式获得这个结果?
【问题讨论】:
-
为什么不直接捕获 http 之后的所有内容,然后将结果提供给 stdlib 中的 urlparser 以确保它是有效的 url