Scaper_search / search.py
gaur3009's picture
Update search.py
fad0ef9 verified
raw
history blame
656 Bytes
from googlesearch import search
import random
def search_google(query, num_results=5):
"""Search Google and return list of URLs."""
try:
# Randomize user agent to avoid blocking
user_agent = random.choice([
"Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)",
"Mozilla/5.0 (X11; Linux x86_64)"
])
return list(search(
query,
num_results=num_results,
advanced=False,
user_agent=user_agent
))
except Exception as e:
print(f"Search error: {e}")
return []