python - 如何使用python从文本文件中获取链接
问题描述
所以我有一个看起来像这样的文本文件
randomthings inside text file "https://linkforvideo.mp4" a lot more random things "https://linkforphoto.jpg"
我想以可点击的格式打印以“.mp4”结尾的链接。我怎么能用python做到这一点?
解决方案
也许使用正则表达式库
import re
word = 'randomthings inside text file "https://linkforvideo.mp4" a lot more random things "https://linkforphoto.jpg"'
link=[]
result = re.search('https://(.*?).mp4', word)
while True:
try:
result_string = result.group(0)
link.append(result_string)
word= word.replace(result_string, "")
result = re.search('https://(.*?).mp4', word)
except : break
print(link)
在这里,您将过滤结果以仅获取以“https://”开头并以“.mp4”结尾的字符串,在获取字符串后,从“word”中删除创建的字符串并再次运行程序直到出现不匹配。
推荐阅读
- android - kotlin 缺少 GoogleMap 的方法
- jquery - 在单击 jquery 时将背景图像设置为名称属性不起作用
- json - 为什么从对象“从不”检索函数的参数
- azure - Azure 函数,Blob 触发器:将数据文件从 Blob 复制到服务器
- android - 在发布版本中启用 R8 后移动应用程序崩溃
- oracle - 甲骨文 | 使用正则表达式导出的 XML 数据
- c# - .NET 核心中的 MD5 哈希是确定性的吗?
- batch-file - 在 Windows 10 上获取当前分辨率的批处理文件
- vue.js - Vuejs在v-model为空时隐藏一个div
- apache - 从 Apache Druid 删除列