an app that uses selenium to scrape a website google.com to extract text
To upload files, please first save the app
import streamlit as st
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
import ssl
st.title("Google.com Scraper")
def scrape_google():
# Set up Chrome options
chrome_options = Options()
chrome_options.add_argument("--headless") # Run in headless mode
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage")
try:
# Initialize the Chrome WebDriver
service = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service, options=chrome_options)
# Navigate to Google
driver.get("https://www.google.com")
# Extract text from the page
page_text = driver.find_element(By.TAG_NAME, "body").text
# Close the browser
driver.quit()
return page_text
except Exception as e:
return f"An error occurred: {str(e)}"
if st.button("Scrape Google"):
with st.spinner("Scraping..."):
result = scrape_google()
st.text_area("Scraped Content", result, height=300)
st.markdown("""
### Note:
This app uses Selenium to scrape Google.com. Please note that:
1. Web scraping should be done responsibly and in accordance with the website's terms of service
2. The app runs in headless mode (without opening a visible browser window)
3. Some websites may block automated access
""")
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?