Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -5,28 +5,31 @@ from bs4 import BeautifulSoup
|
|
| 5 |
import requests
|
| 6 |
from urllib.parse import urljoin, urlparse
|
| 7 |
|
| 8 |
-
def
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
def download_content(url):
|
| 16 |
response = requests.get(url)
|
| 17 |
return response.text
|
| 18 |
|
| 19 |
st.title("Search and Download")
|
| 20 |
-
|
| 21 |
query = st.text_input("Enter your query (e.g. beds)")
|
| 22 |
url = st.text_input("Enter the URL to search from (e.g. https://www.daraz.com.np/)")
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
if
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
st.
|
| 32 |
|
|
|
|
| 5 |
import requests
|
| 6 |
from urllib.parse import urljoin, urlparse
|
| 7 |
|
| 8 |
+
def google_search(query, url):
|
| 9 |
+
google_url = f"https://www.google.com/search?q={query}+site:{url}"
|
| 10 |
+
response = requests.get(google_url)
|
| 11 |
+
soup = BeautifulSoup(response.text, 'html.parser')
|
| 12 |
+
links = soup.find_all('a')
|
| 13 |
+
for link in links:
|
| 14 |
+
href = link.get('href')
|
| 15 |
+
if href and href.startswith('/url?q='):
|
| 16 |
+
return href.split('&sa=U&ved=')[0].replace('/url?q=', '')
|
| 17 |
+
return None
|
| 18 |
|
| 19 |
def download_content(url):
|
| 20 |
response = requests.get(url)
|
| 21 |
return response.text
|
| 22 |
|
| 23 |
st.title("Search and Download")
|
|
|
|
| 24 |
query = st.text_input("Enter your query (e.g. beds)")
|
| 25 |
url = st.text_input("Enter the URL to search from (e.g. https://www.daraz.com.np/)")
|
| 26 |
+
if st.button("Search"):
|
| 27 |
+
link = google_search(query, url)
|
| 28 |
+
if link:
|
| 29 |
+
st.write("First result:", link)
|
| 30 |
+
if st.button("Download content"):
|
| 31 |
+
content = download_content(link)
|
| 32 |
+
st.download_button("Download", content, file_name="content.html")
|
| 33 |
+
else:
|
| 34 |
+
st.write("No results found")
|
| 35 |
|