Created
May 3, 2024 11:42
-
-
Save anxo-outeiral/6905af434178417575ea8b606219769e to your computer and use it in GitHub Desktop.
Extracting Links from a Website Using Python
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
# 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