Spaces:
Sleeping
Sleeping
import streamlit as st | |
from requests_html import HTMLSession | |
def perform_search(search_query): | |
session = HTMLSession() | |
url = f'https://www.bing.com/search?q={search_query}' | |
response = session.get(url) | |
response.html.render(sleep=1) | |
search_results = response.html.find('li.b_algo') | |
results = [] | |
for result in search_results: | |
title = result.find('h2', first=True).text | |
link = result.find('a', first=True).attrs['href'] | |
results.append(f'{title}\n{link}') | |
return results | |
st.title('Web Automation with requests-html') | |
search_query = st.text_input('Enter a search query') | |
if st.button('Search'): | |
results = perform_search(search_query) | |
st.write('Search Results:') | |
for result in results: | |
st.write(result) |