File size: 6,035 Bytes
caa28a1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
import requests
from bs4 import BeautifulSoup
import streamlit as st
from urllib.parse import quote

@st.cache_resource
def display_glossary_entity(k):
    search_urls = {
        "🚀🌌ArXiv": lambda k: f"https://arxiv.org/search/?query={quote(k)}&searchtype=all&source=header",
        "📖Wiki": lambda k: f"https://en.wikipedia.org/wiki/{quote(k)}",
        "🔍Google": lambda k: f"https://www.google.com/search?q={quote(k)}",
        "🔎Bing": lambda k: f"https://www.bing.com/search?q={quote(k)}",
        "🎥YouTube": lambda k: f"https://www.youtube.com/results?search_query={quote(k)}",
        "🐦Twitter": lambda k: f"https://twitter.com/search?q={quote(k)}",
    }
    links_md = ' '.join([f"[{emoji}]({url(k)})" for emoji, url in search_urls.items()])
    st.markdown(f"**{k}** <small>{links_md}</small>", unsafe_allow_html=True)

def perform_search(search_query, search_engine):
    if search_engine == "Google":
        url = f"https://www.google.com/search?q={search_query}"
        response = requests.get(url)
        soup = BeautifulSoup(response.text, "html.parser")
        
        html_content = soup.prettify()
        text_content = soup.get_text()
        links = [link["href"] for link in soup.find_all("a", href=True)]
        images = [img["src"] for img in soup.find_all("img", src=True)]
        
        results = {
            "html": html_content,
            "text": text_content,
            "links": links,
            "images": images
        }
    elif search_engine == "Bing":
        url = f"https://www.bing.com/search?q={search_query}"
        response = requests.get(url)
        soup = BeautifulSoup(response.text, "html.parser")
        
        html_content = soup.prettify()
        text_content = soup.get_text()
        links = [link["href"] for link in soup.find_all("a", href=True)]
        images = [img["src"] for img in soup.find_all("img", src=True)]
        
        results = {
            "html": html_content,
            "text": text_content,
            "links": links,
            "images": images
        }
    elif search_engine == "Wikipedia":
        url = f"https://en.wikipedia.org/w/index.php?search={search_query}"
        response = requests.get(url)
        soup = BeautifulSoup(response.text, "html.parser")
        
        html_content = soup.prettify()
        text_content = soup.get_text()
        links = [link["href"] for link in soup.find_all("a", href=True)]
        images = [img["src"] for img in soup.find_all("img", src=True)]
        
        results = {
            "html": html_content,
            "text": text_content,
            "links": links,
            "images": images
        }
    elif search_engine == "Twitter":
        url = f"https://twitter.com/search?q={search_query}"
        response = requests.get(url)
        soup = BeautifulSoup(response.text, "html.parser")
        
        html_content = soup.prettify()
        text_content = soup.get_text()
        links = [link["href"] for link in soup.find_all("a", href=True)]
        images = [img["src"] for img in soup.find_all("img", src=True)]
        
        results = {
            "html": html_content,
            "text": text_content,
            "links": links,
            "images": images
        }
    
    return results

def main():
    st.set_page_config(page_title="Web Search App", page_icon=":mag:", layout="wide")
    
    st.title("Web Search App")
    st.write("Search Google, Bing, Wikipedia, and Twitter simultaneously!")
    
    search_query = st.text_input("Enter your search query")
    display_glossary_entity(search_query)
    
    col1, col2, col3, col4 = st.columns(4)
    
    with col1:
        st.header("Google Search Results")
        if st.button("Search Google"):
            google_results = perform_search(search_query, "Google")
            st.write("HTML Content:")
            st.code(google_results["html"], language="html")
            st.write("Text Content:")
            st.write(google_results["text"])
            st.write("Links:")
            for link in google_results["links"]:
                st.write(link)
            st.write("Images:")
            for image in google_results["images"]:
                st.image(image)
    
    with col2:
        st.header("Bing Search Results")
        if st.button("Search Bing"):
            bing_results = perform_search(search_query, "Bing")
            st.write("HTML Content:")
            st.code(bing_results["html"], language="html")
            st.write("Text Content:")
            st.write(bing_results["text"])
            st.write("Links:")
            for link in bing_results["links"]:
                st.write(link)
            st.write("Images:")
            for image in bing_results["images"]:
                st.image(image)
    
    with col3:
        st.header("Wikipedia Search Results")
        if st.button("Search Wikipedia"):
            wikipedia_results = perform_search(search_query, "Wikipedia")
            st.write("HTML Content:")
            st.code(wikipedia_results["html"], language="html")
            st.write("Text Content:")
            st.write(wikipedia_results["text"])
            st.write("Links:")
            for link in wikipedia_results["links"]:
                st.write(link)
            st.write("Images:")
            for image in wikipedia_results["images"]:
                st.image(image)
    
    with col4:
        st.header("Twitter Search Results")
        if st.button("Search Twitter"):
            twitter_results = perform_search(search_query, "Twitter")
            st.write("HTML Content:")
            st.code(twitter_results["html"], language="html")
            st.write("Text Content:")
            st.write(twitter_results["text"])
            st.write("Links:")
            for link in twitter_results["links"]:
                st.write(link)
            st.write("Images:")
            for image in twitter_results["images"]:
                st.image(image)

if __name__ == "__main__":
    main()