HS Banner
Back
Use BeautifulSoup in Python to extract links from a web page.

Author: Admin 02/16/2026
Language: Python
Tags: python beautifulsoup


Description:

Use BeautifulSoup in Python to extract all the links by retrieving all the anchor tags from a web page.

Article:

import urllib.request, urllib.parse, urllib.error
from bs4 import BeautifulSoup
import ssl

# Ignore SSL certificate errors
ctx = ssl.create_default_context()
ctx.check_hostname = False
ctx.verify_mode = ssl.CERT_NONE

# Get urls using BeautifulSoup import
url = input("Enter the url to parse: ")
html = urllib.request.urlopen(url, context=ctx).read()
soup = BeautifulSoup(html, "html.parser")

# Retrieve all the anchor tags
tags = soup.find_all("a")
for tag in tags:
    print(tag.get("href", None))
#print(tags)

This is some of the code from my Python course.



Back
Comments
Add Comment
There are no comments yet.