📘 Lesson  ·  Lesson 98

Web Scraping (BeautifulSoup)

About this Project

💡 At a Glance

BeautifulSoup reads a web page's HTML and lets you extract data like titles, links and text.

The Program

Python
import requests
from bs4 import BeautifulSoup

url = "https://example.com"
html = requests.get(url).text
soup = BeautifulSoup(html, "html.parser")

print("Title:", soup.title.text)

# all links on the page
for link in soup.find_all("a"):
    print(link.get("href"))
Title: Example Domain https://www.iana.org/domains/example

Scrape Responsibly

⚠️ Note

Always check a site's robots.txt and terms before scraping. Do not overload servers.

Summary

  • requests fetches the HTML; BeautifulSoup parses it.
  • Use soup.title, soup.find_all() to extract elements.
← Back to Python Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 Live Code Editor

This page's programs are ready here — run them, edit them, and learn. No installation needed.
Powered by OneCompiler. The code loads into the editor automatically — press Run to see the output. If the editor does not open, open it in a new tab.