Want to learn web scraping in Python? In this tutorial, we’ll use BeautifulSoup and Requests to extract data from a website step by step! 🕸️📊
🔹 What You’ll Learn:
✅ What is web scraping?
✅ How to fetch web pages using Requests
✅ How to parse HTML using BeautifulSoup
✅ How to extract book titles and genres from a real website
✅ Ethical web scraping tips
📌 Code & Resources:
import requests
from bs4 import BeautifulSoup
Define the URL
url = "http://books.toscrape.com/"
Send the GET request
response = requests.get(url)
Parse the HTML using BeautifulSoup
soup = BeautifulSoup(response.text, "html.parser")
Find the genre section
genres_list = soup.select(".side_categories ul li a")
Extract and print genres
print("Book Genres:")
for genre in genres_list:
genre_name = genre.text.strip()
genre_link = url + genre["href"] # Make full URL
print(f"- {genre_name}: {genre_link}")
📌 Practice Website: http://books.toscrape.com
🔥 Want more Python tutorials? Subscribe & hit the 🔔 for updates!
👉 Like, Comment & Share if this helped you! 🚀