Spaces:
Running
Running
Rename app.py to package.json
Browse files- app.py +0 -46
- package.json +12 -0
app.py
DELETED
|
@@ -1,46 +0,0 @@
|
|
| 1 |
-
from fastapi import FastAPI
|
| 2 |
-
from playwright.async_api import async_playwright
|
| 3 |
-
|
| 4 |
-
app = FastAPI()
|
| 5 |
-
|
| 6 |
-
@app.get("/search")
|
| 7 |
-
async def search(q: str):
|
| 8 |
-
|
| 9 |
-
results = []
|
| 10 |
-
|
| 11 |
-
async with async_playwright() as p:
|
| 12 |
-
|
| 13 |
-
browser = await p.chromium.launch(
|
| 14 |
-
headless=True,
|
| 15 |
-
args=["--no-sandbox"]
|
| 16 |
-
)
|
| 17 |
-
|
| 18 |
-
page = await browser.new_page()
|
| 19 |
-
|
| 20 |
-
await page.goto(
|
| 21 |
-
f"https://www.google.com/search?q={q}",
|
| 22 |
-
wait_until="networkidle"
|
| 23 |
-
)
|
| 24 |
-
|
| 25 |
-
cards = await page.locator("div.g").all()
|
| 26 |
-
|
| 27 |
-
for card in cards[:10]:
|
| 28 |
-
|
| 29 |
-
try:
|
| 30 |
-
title = await card.locator("h3").inner_text()
|
| 31 |
-
link = await card.locator("a").get_attribute("href")
|
| 32 |
-
|
| 33 |
-
results.append({
|
| 34 |
-
"title": title,
|
| 35 |
-
"url": link
|
| 36 |
-
})
|
| 37 |
-
|
| 38 |
-
except:
|
| 39 |
-
pass
|
| 40 |
-
|
| 41 |
-
await browser.close()
|
| 42 |
-
|
| 43 |
-
return {
|
| 44 |
-
"query": q,
|
| 45 |
-
"results": results
|
| 46 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "google-search-api",
|
| 3 |
+
"version": "1.0.0",
|
| 4 |
+
"type": "module",
|
| 5 |
+
"scripts": {
|
| 6 |
+
"start": "node server.js"
|
| 7 |
+
},
|
| 8 |
+
"dependencies": {
|
| 9 |
+
"express": "^4.21.2",
|
| 10 |
+
"playwright": "^1.53.0"
|
| 11 |
+
}
|
| 12 |
+
}
|