C'è un modo per ottenere uno Zestimate di "Questa casa" per gennaio di ogni anno dal 2015-2020 usando Selenium of Beautiful Soup? [duplicare]
Dal collegamento seguente voglio essere in grado di raschiare i dati. Tuttavia, quando utilizzo Beautiful Soup non sono riuscito a trovarlo nell'html e Beautiful Soup non funzionava. Inoltre, ho pensato che forse potevo usare il selenio per raccogliere questi dati, ma non riesco nemmeno a localizzare questo contenuto. Sai come userei il selenio o Beautiful Soup per ottenere lo Zestimate di "This home" per gennaio di ogni anno dal 2015-2020? Grazie per il vostro aiuto in anticipo. Sto usando Python.
https://www.zillow.com/homedetails/1954-Sandy-Point-Ln-Mount-Pleasant-SC-29466/10938706_zpid/

Risposte
Prova il codice seguente, darà lo Zestimate per la casa.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
import time
options = Options()
user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.50 Safari/537.36'
options.add_argument('user-agent={0}'.format(user_agent))
driver = webdriver.Chrome(options=options)
wait = WebDriverWait(driver, 20)
action = ActionChains(driver)
driver.get("https://www.zillow.com/homedetails/1954-Sandy-Point-Ln-Mount-Pleasant-SC-29466/10938706_zpid/")
Home_Value = wait.until(EC.presence_of_element_located((By.XPATH, "//a[text()='Home value']")))
action.move_to_element(Home_Value).click().perform()
Zestimate = driver.find_element_by_xpath('//*[@id="ds-home-values"]/div/div[1]/div/div[1]/div/div/p').text
print(Zestimate)
Per quanto riguarda - "Gennaio di ogni anno dal 2015-2020?" - Puoi eseguire lo stesso script manualmente a gennaio per ottenere l'ultimo Zestimate. Puoi anche creare un cron job. Ma non sono sicuro di come farlo.
PS - Dopo aver eseguito questo script per circa 3-4 volte, ora sto affrontando un CAPTCHA. C'è una buona spiegazione disponibile su QUESTO link
Per estrarre Zestimate, ad esempio, Zestimate®: $4,232,581
devi indurre WebDriverWait per il element_to_be_clickable()
e puoi utilizzare una delle seguenti strategie di localizzazione :
Utilizzando
XPATH
:driver.get('https://www.zillow.com/homedetails/1954-Sandy-Point-Ln-Mount-Pleasant-SC-29466/10938706_zpid/') print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//span[contains(., 'For sale')]//following::span[contains(@class, 'ds-dashed-underline') and contains(., 'Zestimate')]//ancestor::span[2]"))).text)
Nota : devi aggiungere le seguenti importazioni:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC