Spaces:
Runtime error
Runtime error
Update search.py
Browse files
search.py
CHANGED
@@ -1,5 +1,22 @@
|
|
1 |
from googlesearch import search
|
|
|
2 |
|
3 |
def search_google(query, num_results=5):
|
4 |
"""Search Google and return list of URLs."""
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from googlesearch import search
|
2 |
+
import random
|
3 |
|
4 |
def search_google(query, num_results=5):
|
5 |
"""Search Google and return list of URLs."""
|
6 |
+
try:
|
7 |
+
# Randomize user agent to avoid blocking
|
8 |
+
user_agent = random.choice([
|
9 |
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
|
10 |
+
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)",
|
11 |
+
"Mozilla/5.0 (X11; Linux x86_64)"
|
12 |
+
])
|
13 |
+
|
14 |
+
return list(search(
|
15 |
+
query,
|
16 |
+
num_results=num_results,
|
17 |
+
advanced=False,
|
18 |
+
user_agent=user_agent
|
19 |
+
))
|
20 |
+
except Exception as e:
|
21 |
+
print(f"Search error: {e}")
|
22 |
+
return []
|