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