Eray Bartan Blog

Eray Bartan Blog

Python Web Scraping and create FastAPI

Python Web Scraping and create FastAPI

Subscribe to my newsletter and never miss my upcoming articles

python requests-html ile basit bir veri çekme operasyonu hazırladım. scraper.py dosyam bu şekilde veri çektiğim site : quotes.toscrape.com/tag/inspirational

from requests_html import HTMLSession

class Scraper():
    def scrapedata(self, tag):
        url = f'https://quotes.toscrape.com/tag/{tag}'
        s = HTMLSession()
        r = s.get(url)
        print(r.status_code)

        qlist = []
        quotes = r.html.find('div.quote')

        for q in quotes:
            item = {
                'text' : q.find('span.text', first=True).text.strip(),
                'author' : q.find('small.author', first=True).text.strip()

            }
            print(item)
            qlist.append(item)
        return qlist

quotes = Scraper()
quotes.scrapedata('life')

FastAPI Daha önce NodeJs kullanarak oluşturduğum api server şimdi python altyapısı ile karşımda. Başlangıç içeriklerini izleyerek 127.0.0.1:8000/books url sine gelen books hakkındaki özlü sözler...

from fastapi import FastAPI
from scraper import Scraper

app = FastAPI()
quotes = Scraper()

@app.get("/")
def read_root():
    return {"Hello": "World"}

@app.get("/{cat}")
async def read_item(cat):
    return quotes.scrapedata(cat)
#python#web-scraping#data-science#data-structures#data-analysis
 
Share this

Impressum

Technical Specialties

  • Neo4j Graph Database Beginner Developer
  • Google Data Studio Dashboard Design
  • Micosoft Power BI Dashboard Design

Industry Experience

  • Municiapilty (IT Department, Data Analyst)
  • Real Estate (Web Design, Social Media Publisher, Mailchimp Automation)
  • Hotels & Restaurants (Web Design, Google Ads , Facebook Ads)
  • Sports (Web Design, Mailchimp Campaign)
Proudly part of