Scraper / app.py
Shreyas094's picture
Update app.py
d81cfef verified
import gradio as gr
from GoogleScraper import scrape_with_config, GoogleSearchError
def google_scraper(query):
try:
# Configuration for GoogleScraper
config = {
'use_own_ip': False, # Use proxies
'keyword': query, # The search query
'search_engines': ['google'], # Search engine to scrape
'num_pages_for_keyword': 1, # Number of result pages per keyword
'scrape_method': 'selenium', # Scrape using Selenium for accuracy
'do_caching': False, # Disable caching to get fresh results
}
results = scrape_with_config(config)
output = []
for serp in results['searches']:
for link in serp['results']:
output.append(f"Title: {link['title']}\nLink: {link['link']}")
return "\n\n".join(output) if output else "No results found."
except GoogleSearchError as e:
return f"Error during scraping: {e}"
# Gradio interface
interface = gr.Interface(
fn=google_scraper,
inputs="text",
outputs="text",
title="Google Search Scraper",
description="Enter your search query to scrape Google search results."
)
# Launch interface
if __name__ == "__main__":
interface.launch()