Skip to content

Instantly share code, notes, and snippets.

@anxo-outeiral
Created May 3, 2024 11:42
Show Gist options
  • Save anxo-outeiral/6905af434178417575ea8b606219769e to your computer and use it in GitHub Desktop.
Save anxo-outeiral/6905af434178417575ea8b606219769e to your computer and use it in GitHub Desktop.
Extracting Links from a Website Using Python
# Original code: https://medium.com/@cuncis/extracting-links-from-a-website-using-python-a24e195e6c62
import requests
from bs4 import BeautifulSoup
# send a GET request to the website
url = 'https://www.example.com'
response = requests.get(url)
# parse the HTML content of the page with BeautifulSoup
soup = BeautifulSoup(response.content, 'html.parser')
# find all links on the page
links = soup.find_all('a')
# print the href attribute of each link
for link in links:
print(link.get('href'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment