使用python和urllib3从网页检索链接

时间:2019-07-12 14:42:25

标签: python-3.x urllib3

假设我只安装了urllib3软件包(标准的anaconda安装)。

用户如何使用urllib3从网页获取所有链接?

我还看到了与BeautifulSoup和urllib2的其他链接,但是有没有urllib3的有效示例?

示例: retrieve links from web page using python and BeautifulSoup

我尝试对urllib和urllib2使用例程并附加到urllib3,但这会产生错误消息:

AttributeError: module 'urllib3' has no attribute 'urlopen'

我的代码:

import urllib3
import re


#connect to a URL
url = 'https://www.londonstockexchange.com/exchange/news/market-news/market-news-home.html'
website = urllib3.urlopen(url)

#read html code
html = website.read()

#use re.findall to get all the links
links = re.findall('"((http|ftp)s?://.*?)"', html)

print(links)

0 个答案:

没有答案