Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import time
|
| 4 |
-
import
|
|
|
|
| 5 |
import chromedriver_autoinstaller
|
| 6 |
from selenium import webdriver
|
| 7 |
from selenium.webdriver.common.by import By
|
|
@@ -10,7 +11,13 @@ from selenium.webdriver.chrome.options import Options
|
|
| 10 |
from selenium.webdriver.support.ui import WebDriverWait
|
| 11 |
from selenium.webdriver.support import expected_conditions as EC
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def scrape_redfin(zipcode):
|
|
|
|
| 14 |
chromedriver_autoinstaller.install() # Ensure the correct chromedriver version is installed
|
| 15 |
|
| 16 |
options = Options()
|
|
@@ -22,11 +29,7 @@ def scrape_redfin(zipcode):
|
|
| 22 |
options.add_argument("start-maximized")
|
| 23 |
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
|
| 24 |
|
| 25 |
-
|
| 26 |
-
chrome_path = shutil.which("google-chrome") or shutil.which("chrome")
|
| 27 |
-
if chrome_path:
|
| 28 |
-
options.binary_location = chrome_path
|
| 29 |
-
|
| 30 |
driver = webdriver.Chrome(options=options)
|
| 31 |
url = f"https://www.redfin.com/zipcode/{zipcode}"
|
| 32 |
driver.get(url)
|
|
@@ -107,6 +110,7 @@ if st.button("Scrape Data"):
|
|
| 107 |
|
| 108 |
|
| 109 |
|
|
|
|
| 110 |
## working best code ever
|
| 111 |
|
| 112 |
# import streamlit as st
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import pandas as pd
|
| 3 |
import time
|
| 4 |
+
import os
|
| 5 |
+
import subprocess
|
| 6 |
import chromedriver_autoinstaller
|
| 7 |
from selenium import webdriver
|
| 8 |
from selenium.webdriver.common.by import By
|
|
|
|
| 11 |
from selenium.webdriver.support.ui import WebDriverWait
|
| 12 |
from selenium.webdriver.support import expected_conditions as EC
|
| 13 |
|
| 14 |
+
def install_chrome():
|
| 15 |
+
if not os.path.exists("/usr/bin/google-chrome"):
|
| 16 |
+
subprocess.run(["apt-get", "update"])
|
| 17 |
+
subprocess.run(["apt-get", "install", "-y", "chromium-browser"])
|
| 18 |
+
|
| 19 |
def scrape_redfin(zipcode):
|
| 20 |
+
install_chrome() # Ensure Chrome/Chromium is installed
|
| 21 |
chromedriver_autoinstaller.install() # Ensure the correct chromedriver version is installed
|
| 22 |
|
| 23 |
options = Options()
|
|
|
|
| 29 |
options.add_argument("start-maximized")
|
| 30 |
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
|
| 31 |
|
| 32 |
+
options.binary_location = "/usr/bin/chromium-browser" # Use Chromium
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
driver = webdriver.Chrome(options=options)
|
| 34 |
url = f"https://www.redfin.com/zipcode/{zipcode}"
|
| 35 |
driver.get(url)
|
|
|
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
+
|
| 114 |
## working best code ever
|
| 115 |
|
| 116 |
# import streamlit as st
|