File size: 1,306 Bytes
7c6b062
d81cfef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7c6b062
 
d81cfef
7c6b062
d81cfef
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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()