Spaces:
Paused
Paused
upload mcp_serpapi.py
Browse files- mcp_serpapi.py +20 -0
mcp_serpapi.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from serpapi import GoogleSearch
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
SERPAPI_KEY = os.getenv("SERPAPI_KEY")
|
| 5 |
+
|
| 6 |
+
def search_pdf_url(query):
|
| 7 |
+
params = {
|
| 8 |
+
"engine": "google",
|
| 9 |
+
"q": query,
|
| 10 |
+
"api_key": SERPAPI_KEY
|
| 11 |
+
}
|
| 12 |
+
search = GoogleSearch(params)
|
| 13 |
+
results = search.get_dict()
|
| 14 |
+
|
| 15 |
+
# Extract first PDF URL
|
| 16 |
+
for res in results.get("organic_results", []):
|
| 17 |
+
link = res.get("link", "")
|
| 18 |
+
if link.lower().endswith(".pdf"):
|
| 19 |
+
return link
|
| 20 |
+
return None
|