Skip to content

Instantly share code, notes, and snippets.

@perymerdeka
Created August 13, 2025 07:41
Show Gist options
  • Select an option

  • Save perymerdeka/3e1730c84939333b5e34711ef1edfa96 to your computer and use it in GitHub Desktop.

Select an option

Save perymerdeka/3e1730c84939333b5e34711ef1edfa96 to your computer and use it in GitHub Desktop.
from fastapi import FastAPI
from quotes import fetch_quotes # <- ini scraper kamu dari file uotes.py
app = FastAPI()
@app.get("/")
async def root():
return {"message": "Hello World"}
@app.get("/quotes")
async def get_quotes():
return {"quotes": fetch_quotes() # <- ini adalah import dari scraper kamu}
@perymerdeka
Copy link
Author

import requests
from bs4 import BeautifulSoup

def fetch_quotes():
    url = "https://quotes.toscrape.com/"
    response = requests.get(url)
    soup = BeautifulSoup(response.text, "html.parser")
    quotes = soup.find_all("span", class_="text")
    return [quote.text for quote in quotes]

ini scraper nya

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment