Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,6 +1,8 @@
|
|
| 1 |
from fastapi import FastAPI, HTTPException
|
| 2 |
from playwright.sync_api import sync_playwright
|
| 3 |
import os
|
|
|
|
|
|
|
| 4 |
|
| 5 |
app = FastAPI(title="Neon Anime Scraper")
|
| 6 |
|
|
@@ -38,27 +40,27 @@ def search_anime(keyword: str):
|
|
| 38 |
raise HTTPException(status_code=400, detail="Keyword is required")
|
| 39 |
|
| 40 |
try:
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
|
| 63 |
return {"keyword": keyword, "results": results}
|
| 64 |
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException
|
| 2 |
from playwright.sync_api import sync_playwright
|
| 3 |
import os
|
| 4 |
+
import requests
|
| 5 |
+
from bs4 import BeautifulSoup
|
| 6 |
|
| 7 |
app = FastAPI(title="Neon Anime Scraper")
|
| 8 |
|
|
|
|
| 40 |
raise HTTPException(status_code=400, detail="Keyword is required")
|
| 41 |
|
| 42 |
try:
|
| 43 |
+
url = f"https://hianime.to/search?keyword={keyword}"
|
| 44 |
+
headers = {
|
| 45 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
| 46 |
+
"AppleWebKit/537.36 (KHTML, like Gecko) "
|
| 47 |
+
"Chrome/120.0.0.0 Safari/537.36"
|
| 48 |
+
}
|
| 49 |
+
resp = requests.get(url, headers=headers, timeout=15)
|
| 50 |
+
if resp.status_code != 200:
|
| 51 |
+
raise HTTPException(status_code=resp.status_code, detail="Failed to fetch search page")
|
| 52 |
+
|
| 53 |
+
soup = BeautifulSoup(resp.text, "html.parser")
|
| 54 |
+
items = soup.select(".flw-item")
|
| 55 |
+
results = []
|
| 56 |
+
for item in items:
|
| 57 |
+
title_elem = item.select_one(".film-name a")
|
| 58 |
+
thumb_elem = item.select_one("img")
|
| 59 |
+
results.append({
|
| 60 |
+
"title": title_elem.text.strip() if title_elem else None,
|
| 61 |
+
"url": title_elem["href"] if title_elem else None,
|
| 62 |
+
"thumbnail": thumb_elem["src"] if thumb_elem else None
|
| 63 |
+
})
|
| 64 |
|
| 65 |
return {"keyword": keyword, "results": results}
|
| 66 |
|