Makima57 commited on
Commit
898b622
·
verified ·
1 Parent(s): 9f21b7a

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +9 -14
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, 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:
@@ -20,18 +20,13 @@ def download_content(url):
20
  response = requests.get(url)
21
  return response.text
22
 
23
- st.title("Search and Download")
24
-
25
- query = st.text_input("Enter your query (e.g. beds)")
26
- url = st.text_input("Enter the URL to search from (e.g. https://www.daraz.com.np/)")
27
- search_button = st.button("Search")
28
-
29
- if search_button:
30
- link = google_search(query, url)
31
  if link:
32
- st.write(f"First result: {link}")
33
- download_button = st.button("Download Content")
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: