File size: 1,711 Bytes
0d9ed80
 
 
73a33e7
0d9ed80
 
73a33e7
 
0d9ed80
73a33e7
 
 
 
0d9ed80
73a33e7
0d9ed80
 
73a33e7
 
0d9ed80
 
73a33e7
 
0d9ed80
73a33e7
0d9ed80
 
73a33e7
 
0d9ed80
73a33e7
 
0d9ed80
73a33e7
 
0d9ed80
73a33e7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0d9ed80
73a33e7
 
0d9ed80
810c675
0d9ed80
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

# app.py
import streamlit as st
from googlesearch import search
import requests

# Function to perform Google search and return the first link
def google_search(query):
    try:
        # Perform the search and get an iterator of results
        search_results = search(query, num_results=10)  # Get up to 10 results
        first_link = next(search_results, None)  # Get the first result
        return first_link
    except Exception as e:
        st.error(f"An error occurred: {e}")
        return None

# Function to fetch webpage content
def fetch_webpage_content(url):
    try:
        response = requests.get(url)
        response.raise_for_status()  # Check if the request was successful
        return response.text
    except Exception as e:
        st.error(f"Failed to fetch the webpage content: {e}")
        return None

# Streamlit app UI
st.title("Search Link Finder")

# Input field for search query
query = st.text_input("Enter search query", "")

# Button to trigger search
if st.button("Search"):
    if query:
        first_link = google_search(query)
        if first_link:
            st.success(f"First link: [Click here]({first_link})")

            # Fetch webpage content
            webpage_content = fetch_webpage_content(first_link)

            if webpage_content:
                # Download button for the webpage content
                st.download_button(
                    label="Download Webpage Content",
                    data=webpage_content,
                    file_name="webpage_content.html",
                    mime="text/html"
                )
        else:
            st.warning("No results found")
    else:
        st.error("Please enter a query")