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 |
-
# Custom CSS
|
| 6 |
def load_css():
|
| 7 |
st.markdown("""
|
| 8 |
<style>
|
|
@@ -54,12 +54,15 @@ def load_css():
|
|
| 54 |
color: #545454;
|
| 55 |
font-size: 14px;
|
| 56 |
}
|
| 57 |
-
.
|
|
|
|
| 58 |
text-align: center;
|
| 59 |
-
margin-top: 50px;
|
| 60 |
}
|
| 61 |
-
.
|
| 62 |
-
|
|
|
|
|
|
|
|
|
|
| 63 |
}
|
| 64 |
</style>
|
| 65 |
""", unsafe_allow_html=True)
|
|
@@ -72,7 +75,7 @@ def search_google(query, proxy=None):
|
|
| 72 |
url = f'https://www.google.com/search?q={query.replace(" ", "+")}&hl=en'
|
| 73 |
proxies = {"http": proxy, "https": proxy} if proxy else None
|
| 74 |
response = requests.get(url, headers=headers, proxies=proxies, timeout=10)
|
| 75 |
-
if "detected unusual traffic" in response.text.lower():
|
| 76 |
return None, True
|
| 77 |
return response.text, False
|
| 78 |
|
|
@@ -89,7 +92,7 @@ def parse_search_results(html_content):
|
|
| 89 |
|
| 90 |
# Streamlit App
|
| 91 |
def main():
|
| 92 |
-
st.set_page_config(page_title="Google Search Clone", layout="centered")
|
| 93 |
load_css()
|
| 94 |
|
| 95 |
st.markdown('<div class="search-bar">', unsafe_allow_html=True)
|
|
@@ -102,23 +105,26 @@ def main():
|
|
| 102 |
html_content, captcha_detected = search_google(query)
|
| 103 |
|
| 104 |
if captcha_detected:
|
| 105 |
-
st.
|
| 106 |
-
<div class="captcha-warning">
|
| 107 |
-
<h3>CAPTCHA Detected</h3>
|
| 108 |
-
<p>Google has detected unusual traffic from this application. Please solve the CAPTCHA manually or try again later.</p>
|
| 109 |
-
</div>
|
| 110 |
-
""", unsafe_allow_html=True)
|
| 111 |
return
|
| 112 |
|
| 113 |
if html_content:
|
| 114 |
search_results = parse_search_results(html_content)
|
| 115 |
-
for result in search_results:
|
| 116 |
st.markdown(f"""
|
| 117 |
<div class="search-result">
|
| 118 |
<h3><a href="{result['link']}" target="_blank">{result['title']}</a></h3>
|
| 119 |
<p>{result['snippet']}</p>
|
|
|
|
|
|
|
| 120 |
</div>
|
| 121 |
""", unsafe_allow_html=True)
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
if __name__ == "__main__":
|
| 124 |
main()
|
|
|
|
| 2 |
from bs4 import BeautifulSoup
|
| 3 |
import streamlit as st
|
| 4 |
|
| 5 |
+
# Custom CSS for clean UI
|
| 6 |
def load_css():
|
| 7 |
st.markdown("""
|
| 8 |
<style>
|
|
|
|
| 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)
|
|
|
|
| 75 |
url = f'https://www.google.com/search?q={query.replace(" ", "+")}&hl=en'
|
| 76 |
proxies = {"http": proxy, "https": proxy} if proxy else None
|
| 77 |
response = requests.get(url, headers=headers, proxies=proxies, timeout=10)
|
| 78 |
+
if "detected unusual traffic" in response.text.lower():
|
| 79 |
return None, True
|
| 80 |
return response.text, False
|
| 81 |
|
|
|
|
| 92 |
|
| 93 |
# Streamlit App
|
| 94 |
def main():
|
| 95 |
+
st.set_page_config(page_title="Google Search Clone with Safe Navigation", layout="centered")
|
| 96 |
load_css()
|
| 97 |
|
| 98 |
st.markdown('<div class="search-bar">', unsafe_allow_html=True)
|
|
|
|
| 105 |
html_content, captcha_detected = search_google(query)
|
| 106 |
|
| 107 |
if captcha_detected:
|
| 108 |
+
st.error("CAPTCHA detected. Please try again later or reduce search frequency.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
return
|
| 110 |
|
| 111 |
if html_content:
|
| 112 |
search_results = parse_search_results(html_content)
|
| 113 |
+
for idx, result in enumerate(search_results, start=1):
|
| 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 |
+
<button onclick="window.open('{result['link']}', '_blank')">Visit Website</button>
|
| 119 |
+
<button onclick="window.location.href='/safe_view?url={result['link']}'">Preview Securely</button>
|
| 120 |
</div>
|
| 121 |
""", unsafe_allow_html=True)
|
| 122 |
|
| 123 |
+
# Iframe secure preview for websites
|
| 124 |
+
if "safe_view" in st.experimental_get_query_params():
|
| 125 |
+
url = st.experimental_get_query_params().get("url", [None])[0]
|
| 126 |
+
if url:
|
| 127 |
+
st.markdown(f"<div class='iframe-container'><iframe src='{url}'></iframe></div>", unsafe_allow_html=True)
|
| 128 |
+
|
| 129 |
if __name__ == "__main__":
|
| 130 |
main()
|