Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from requests_html import HTMLSession
|
3 |
+
|
4 |
+
def perform_search(search_query):
|
5 |
+
session = HTMLSession()
|
6 |
+
url = f'https://www.bing.com/search?q={search_query}'
|
7 |
+
response = session.get(url)
|
8 |
+
response.html.render(sleep=1)
|
9 |
+
search_results = response.html.find('li.b_algo')
|
10 |
+
results = []
|
11 |
+
for result in search_results:
|
12 |
+
title = result.find('h2', first=True).text
|
13 |
+
link = result.find('a', first=True).attrs['href']
|
14 |
+
results.append(f'{title}\n{link}')
|
15 |
+
return results
|
16 |
+
|
17 |
+
st.title('Web Automation with requests-html')
|
18 |
+
search_query = st.text_input('Enter a search query')
|
19 |
+
if st.button('Search'):
|
20 |
+
results = perform_search(search_query)
|
21 |
+
st.write('Search Results:')
|
22 |
+
for result in results:
|
23 |
+
st.write(result)
|