使用re提取网址

时间:2018-11-05 15:54:18

标签: python regex

我正在尝试使用re从我抓取的内容中提取网址。我正在使用下面的代码提取下面的数据,但它似乎是空的。我对re不是很熟悉。你能告诉我如何提取网址吗?

match = ["http://www.stats.gov.cn/tjsj/zxfb/201811/t20181105_1631364.html';", "http://www.stats.gov.cn'+urlstr+'"]

url = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', match`

#print url just prints both. I only need the match = "http://www.stats.gov.cn/tjsj/zxfb/ANYTHINGHERE/ANYTHINGHERE.html"

print(url)

Expected Output = ["http://www.stats.gov.cn/tjsj/zxfb/201811/t20181105_1631364.html';"]

1 个答案:

答案 0 :(得分:0)

好的,我找到了解决方案。 。+查找statically resolved type parameters和.html之间的任意数量的字符。感谢您的帮助。

match = ["http://www.stats.gov.cn/tjsj/zxfb/201811/t20181105_1631364.html';", "http://www.stats.gov.cn'+urlstr+'"]

url = re.findall('http://www.stats.gov.cn/.+.html', str(match))

print(url)

Expected Output = ["http://www.stats.gov.cn/tjsj/zxfb/201811/t20181105_1631364.html"]
相关问题