🟡 Advanced Python · Lesson 28
Web Scraping Basics
Web Scraping Basics क्या है?
Web Scraping Basics ka matlab hai: Web scraping extracts information from web pages. Always follow website rules and use scraping ethically. Simple words me, ye topic practical Python programs likhne me direct use hota hai.
Is topic ko sirf definition ke liye nahi, balki reading public web pages responsibly jaise real examples ke liye practice karein.
यह क्यों सीखना जरूरी है?
- Ye reading public web pages responsibly me kaam aata hai.
- Ye extracting HTML tables se bhi connected hai.
- Isse aap code ka output aur errors better samajh paate hain.
Important Terms
| Term | Meaning |
|---|---|
| HTML | Markup language used to create web pages. |
| BeautifulSoup | Python library commonly used to parse HTML. |
| select | select is an important term in this topic. |
| ethics | ethics is an important term in this topic. |
| robots.txt | File that tells crawlers which pages may be accessed. |
Syntax / Basic Pattern
Basic idea: pehle data तैयार करें, phir Python logic apply करें, aur finally result display करें.
Basic Pattern
from bs4 import BeautifulSoup html_text = """ <html><body> <h1>Python Course</h1> <p class="price">Free</p> </body></html> """ soup = BeautifulSoup(html_text, "html.parser")
Complete Example Program
Python – web-scraping-basics.py
from bs4 import BeautifulSoup
html_text = """
<html><body>
<h1>Python Course</h1>
<p class="price">Free</p>
</body></html>
"""
soup = BeautifulSoup(html_text, "html.parser")
print(soup.find("h1").text)
print(soup.select_one(".price").text)Expected Output
Python Course
Free
Program Explanation
from bs4 import BeautifulSoupimports ready-made features from a module/library.html_text = """stores a value in html_text.<html><body>performs the next step of the program logic.<h1>Python Course</h1>performs the next step of the program logic.<p class="price">Free</p>stores a value in <p class.</body></html>performs the next step of the program logic."""performs the next step of the program logic.
Practical Uses
- Reading public web pages responsibly.
- Extracting html tables.
- Automating repetitive browsing.
Common Mistakes
- Making code complex when a simple function or class is enough.
- Not handling possible errors or edge cases.
- Mixing project dependencies instead of using a virtual environment.
Practice Tasks
- Program ko
web-scraping-basics.pyfile me type karke run karein. - Values change karke output compare karein.
- reading public web pages responsibly par ek छोटा example banayen.
- Logic ko apne words me 5 lines me likhein.
सारांश
Web Scraping Basics ko tab complete maanenge jab aap iska meaning, example, output aur practical use clearly explain kar saken.
💻 लाइव कोड एडिटर
इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.