如何从一堆URL中提取URI?

时间:2019-05-13 13:11:22

标签: python

我有一堆网址。 而且我必须从网址中提取所有uri。

例如:

https://home/a/b/c,
https://home/d/e/f,
https://home/g/h/i,
https://home/j/k/l

我必须在python中https://home/之后提取所有内容。

1 个答案:

答案 0 :(得分:2)

非常简单,只需使用str.split()

>>> str = "https://home/a/b/c"
>>> str.split("https://home/")[1]
a/b/c

因此获取网址列表:

urls = ["https://home/a/b/c", "https://home/d/e/f",
        "https://home/g/h/i", "https://home/j/k/l"]

new_urls = [url.split("https://home/")[1] for url in urls]
print(new_urls)
  

输出:

['a/b/c', 'd/e/f', 'g/h/i', 'j/k/l']