Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -5,9 +5,9 @@ from bs4 import BeautifulSoup
|
|
| 5 |
import requests
|
| 6 |
from urllib.parse import urljoin, urlparse
|
| 7 |
|
| 8 |
-
def google_search(query
|
| 9 |
-
google_url = f"https://www.google.com/search?q={query}
|
| 10 |
-
response = requests.get(google_url)
|
| 11 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 12 |
links = soup.find_all('a')
|
| 13 |
for link in links:
|
|
@@ -20,18 +20,13 @@ def download_content(url):
|
|
| 20 |
response = requests.get(url)
|
| 21 |
return response.text
|
| 22 |
|
| 23 |
-
st.title("Search
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
search_button = st.button("Search")
|
| 28 |
-
|
| 29 |
-
if search_button:
|
| 30 |
-
link = google_search(query, url)
|
| 31 |
if link:
|
| 32 |
-
st.write(
|
| 33 |
-
|
| 34 |
-
if download_button:
|
| 35 |
content = download_content(link)
|
| 36 |
st.download_button("Download", content, file_name="content.html")
|
| 37 |
else:
|
|
|
|
| 5 |
import requests
|
| 6 |
from urllib.parse import urljoin, urlparse
|
| 7 |
|
| 8 |
+
def google_search(query):
|
| 9 |
+
google_url = f"https://www.google.com/search?q={query}"
|
| 10 |
+
response = requests.get(google_url, headers={"User-Agent": "Mozilla/5.0"})
|
| 11 |
soup = BeautifulSoup(response.text, 'html.parser')
|
| 12 |
links = soup.find_all('a')
|
| 13 |
for link in links:
|
|
|
|
| 20 |
response = requests.get(url)
|
| 21 |
return response.text
|
| 22 |
|
| 23 |
+
st.title("Google Search")
|
| 24 |
+
query = st.text_input("Enter your query")
|
| 25 |
+
if st.button("Search"):
|
| 26 |
+
link = google_search(query)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
if link:
|
| 28 |
+
st.write("First result:", link)
|
| 29 |
+
if st.button("Download content"):
|
|
|
|
| 30 |
content = download_content(link)
|
| 31 |
st.download_button("Download", content, file_name="content.html")
|
| 32 |
else:
|