从20152020年起,有没有办法用硒靓汤来估算每年1月的“这个家”的热度?

2024-05-15 13:15:00 发布

您现在位置:Python中文网/ 问答频道 /正文

从下面的链接中,我希望能够获取数据。然而,当我使用Beautiful Soup时,我无法在html中找到它,Beautiful Soup无法工作。此外,我想也许我可以使用selenium来获取这些数据,但我也找不到这些内容。你知道我会如何使用硒或靓汤来获得2015-2020年每年1月的“这个家”的热度吗?提前谢谢你的帮助。我正在使用Python

https://www.zillow.com/homedetails/1954-Sandy-Point-Ln-Mount-Pleasant-SC-29466/10938706_zpid/

enter image description here


Tags: 数据httpscom内容链接htmlwwwselenium
2条回答

请尝试下面的代码,它将给出家庭的Zestimate

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)

关于“2015-2020年每年1月?”——您可以在1月手动运行相同的脚本以获得最新的Zestimate。您还可以创建cron作业。但我不知道该怎么做

另外,在运行这个脚本大约3-4次之后,我现在面临一个验证码。在THIS链接上有一个很好的解释

要提取ZestimateZestimate®: $4,232,581,您必须为element_to_be_clickable()诱导WebDriverWait,并且您可以使用以下任一Locator Strategies

  • 使用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)
    
  • 注意:您必须添加以下导入:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    

相关问题 更多 >