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

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

问题描述

关于:使用 Python 查找文本中的超链接(推特相关)

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

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 的编辑,我劫持了 使用 Python 查找文本中的超链接(twitter 相关) 并想出了这个:

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天全站免登陆