-
Notifications
You must be signed in to change notification settings - Fork 0
/
AIScrape.py
35 lines (31 loc) · 1.06 KB
/
AIScrape.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from dotenv import load_dotenv
import streamlit as st
import openai
import os
load_dotenv()
def scrape_website(url):
chrome_options = Options()
chrome_options.add_argument('--headless') # Run in headless mode for no GUI
service = Service(executable_path='C:/chromedriver/chromedriver.exe') # Update this path
driver = webdriver.Chrome(service=service, options=chrome_options)
try:
driver.get(url)
products = [elem.text for elem in driver.find_elements(By.CLASS_NAME, 'product-class')]
except Exception as e:
products = [str(e)]
finally:
driver.quit()
return products
st.title('AI Scrape')
url = st.text_input('Enter URL to scrape')
if st.button('Scrape'):
if url:
scraped_data = scrape_website(url)
st.write('Scraped Data:')
st.write(scraped_data)
else:
st.error('Please enter a valid URL.')