Python
84 ~35 dk
Web Scraping (BeautifulSoup)
Web Scraping
C:\> pip install requests beautifulsoup4
Successfully installed...import requests
from bs4 import BeautifulSoup
# Web sayfası çek
url = "https://books.toscrape.com"
r = requests.get(url)
soup = BeautifulSoup(r.text, "html.parser")
# Kitap başlıklarını bul
kitaplar = soup.find_all("article", class_="product_pod")
for kitap in kitaplar[:5]:
baslik = kitap.h3.a["title"]
fiyat = kitap.find("p", class_="price_color").text
print(f"📖 {baslik} - {fiyat}")>>> python scraper.py
📖 A Light in the Attic - £51.77
📖 Tipping the Velvet - £53.74
📖 Soumission - £50.10
📖 Sharp Objects - £47.82
📖 Sapiens - £54.23⚠️ Dikkat: Web scraping yaparken sitenin robots.txt dosyasını ve kullanım şartlarını kontrol edin. Etik kurallara uyun.
🎯 Alıştırmalar
- Hava durumu sitesinden sıcaklık bilgisi çeken program
- Bir haber sitesinden başlıkları çekip dosyaya kaydeden program