File size: 673 Bytes
f937b53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
from fastapi import FastAPI
from newspaper import Article
from bs4 import BeautifulSoup
import requests

app = FastAPI()

@app.get("/peruvian_soccer_news")
def get_news():
    url = "https://ovacion.pe/"  # Replace with actual URL
    response = requests.get(url)
    soup = BeautifulSoup(response.content, "html.parser")
    
    # Example: Extract headlines and links
    articles = []
    for item in soup.select(".news-item"):  # Adjust to match actual site structure
        title = item.select_one(".headline").get_text(strip=True)
        link = item.select_one("a")["href"]
        articles.append({"title": title, "link": link})

    return {"articles": articles}