在Python中提取URL [英] Extracting a URL in Python

查看:104
本文介绍了在Python中提取URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于以下内容:使用Python在文本中查找超链接(与Twitter相关)

如何仅提取网址,以便将其放入列表/数组中?

How can I extract just the url so I can put it into a list/array?

让我澄清一下,我不想将URL解析为片段.我想从字符串的文本中提取URL并将其放入数组中.谢谢!

Let me clarify, I don't want to parse the URL into pieces. I want to extract the URL from the text of the string to put it into an array. Thanks!

推荐答案

为响应OP的编辑,我劫持了

In response to the OP's edit I hijacked Find Hyperlinks in Text using Python (twitter related) and came up with this:

import re

myString = "This is my tweet check it out http://example.com/blah"

print(re.search("(?P<url>https?://[^\s]+)", myString).group("url"))

这篇关于在Python中提取URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆