Created
March 2, 2020 08:41
-
-
Save kvabapo/558f7aa8297d0fc254026e7646e835bc to your computer and use it in GitHub Desktop.
Scrape all links in a webpage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import urllib3 | |
import re | |
http = urllib3.PoolManager() | |
def getLinks(url): | |
html_page = http.request('GET', url) | |
soup = BeautifulSoup(html_page.data) | |
links = [] | |
for link in soup.findAll('a', attrs={'href': re.compile("^http://")}): | |
links.append(link.get('href')) | |
return links |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment