Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import requests
|
|
2 |
from bs4 import BeautifulSoup
|
3 |
import streamlit as st
|
4 |
|
5 |
-
#
|
6 |
def load_css():
|
7 |
st.markdown("""
|
8 |
<style>
|
@@ -54,16 +54,6 @@ def load_css():
|
|
54 |
color: #545454;
|
55 |
font-size: 14px;
|
56 |
}
|
57 |
-
.iframe-container {
|
58 |
-
margin-top: 20px;
|
59 |
-
text-align: center;
|
60 |
-
}
|
61 |
-
.iframe-container iframe {
|
62 |
-
width: 80%;
|
63 |
-
height: 600px;
|
64 |
-
border: 1px solid #ccc;
|
65 |
-
border-radius: 8px;
|
66 |
-
}
|
67 |
</style>
|
68 |
""", unsafe_allow_html=True)
|
69 |
|
@@ -92,7 +82,7 @@ def parse_search_results(html_content):
|
|
92 |
|
93 |
# Streamlit App
|
94 |
def main():
|
95 |
-
st.set_page_config(page_title="Google Search Clone with
|
96 |
load_css()
|
97 |
|
98 |
st.markdown('<div class="search-bar">', unsafe_allow_html=True)
|
@@ -110,21 +100,28 @@ def main():
|
|
110 |
|
111 |
if html_content:
|
112 |
search_results = parse_search_results(html_content)
|
113 |
-
for
|
114 |
st.markdown(f"""
|
115 |
<div class="search-result">
|
116 |
<h3><a href="{result['link']}" target="_blank">{result['title']}</a></h3>
|
117 |
<p>{result['snippet']}</p>
|
118 |
-
<
|
119 |
-
<button onclick="window.location.href='/safe_view?url={result['link']}'">Preview Securely</button>
|
120 |
</div>
|
121 |
""", unsafe_allow_html=True)
|
122 |
|
123 |
-
#
|
124 |
-
if "
|
125 |
url = st.query_params.get("url", [None])[0]
|
126 |
if url:
|
127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
128 |
|
129 |
if __name__ == "__main__":
|
130 |
main()
|
|
|
2 |
from bs4 import BeautifulSoup
|
3 |
import streamlit as st
|
4 |
|
5 |
+
# CSS for UI
|
6 |
def load_css():
|
7 |
st.markdown("""
|
8 |
<style>
|
|
|
54 |
color: #545454;
|
55 |
font-size: 14px;
|
56 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
</style>
|
58 |
""", unsafe_allow_html=True)
|
59 |
|
|
|
82 |
|
83 |
# Streamlit App
|
84 |
def main():
|
85 |
+
st.set_page_config(page_title="Google Search Clone with Secure Navigation", layout="centered")
|
86 |
load_css()
|
87 |
|
88 |
st.markdown('<div class="search-bar">', unsafe_allow_html=True)
|
|
|
100 |
|
101 |
if html_content:
|
102 |
search_results = parse_search_results(html_content)
|
103 |
+
for result in search_results:
|
104 |
st.markdown(f"""
|
105 |
<div class="search-result">
|
106 |
<h3><a href="{result['link']}" target="_blank">{result['title']}</a></h3>
|
107 |
<p>{result['snippet']}</p>
|
108 |
+
<a href="/safe_preview?url={result['link']}" target="_self">Secure Preview</a>
|
|
|
109 |
</div>
|
110 |
""", unsafe_allow_html=True)
|
111 |
|
112 |
+
# Display website securely
|
113 |
+
if "safe_preview" in st.query_params:
|
114 |
url = st.query_params.get("url", [None])[0]
|
115 |
if url:
|
116 |
+
try:
|
117 |
+
response = requests.get(url, timeout=10)
|
118 |
+
if response.status_code == 200:
|
119 |
+
st.write(f"### Preview of: {url}")
|
120 |
+
st.code(response.text[:2000], language='html') # Display HTML preview
|
121 |
+
else:
|
122 |
+
st.error(f"Failed to fetch the website. Status code: {response.status_code}")
|
123 |
+
except Exception as e:
|
124 |
+
st.error(f"Error fetching the website: {str(e)}")
|
125 |
|
126 |
if __name__ == "__main__":
|
127 |
main()
|