มีวิธีรับ Zestimate ของ“ บ้านหลังนี้” ในเดือนมกราคมของทุกปีตั้งแต่ปี 2015-2020 โดยใช้ซุปซีลีเนียมที่สวยงามหรือไม่? [ซ้ำ]

Aug 17 2020

จากลิงค์ต่อไปนี้ฉันต้องการที่จะขูดข้อมูล อย่างไรก็ตามเมื่อฉันใช้ Beautiful Soup ฉันไม่พบใน html และ Beautiful soup ก็ไม่ทำงาน นอกจากนี้ฉันคิดว่าฉันอาจใช้ซีลีเนียมเพื่อขูดข้อมูลนี้ได้ แต่ฉันไม่สามารถค้นหาเนื้อหานี้ได้เช่นกัน คุณรู้หรือไม่ว่าฉันจะใช้ซีลีเนียมหรือซุปที่สวยงามเพื่อรับ Zestimate ของ "บ้านหลังนี้" ในเดือนมกราคมของทุกปีตั้งแต่ปี 2558-2563 ได้อย่างไร ขอบคุณสำหรับความช่วยเหลือของคุณล่วงหน้า ฉันใช้ Python

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

คำตอบ

SwaroopHumane Aug 17 2020 at 15:05

ลองใช้รหัสด้านล่างมันจะให้ 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)

เกี่ยวกับ - "มกราคมของทุกปีตั้งแต่ปี 2558-2563?" - คุณสามารถเรียกใช้สคริปต์เดียวกันด้วยตนเองในเดือนมกราคมเพื่อรับ Zestimate ล่าสุด คุณยังสามารถสร้างงาน cron แต่ฉันไม่แน่ใจว่าจะทำอย่างไร

PS - หลังจากเรียกใช้สคริปต์นี้ประมาณ 3-4 ครั้งตอนนี้ฉันกำลังเผชิญกับ CAPTCHA มีคำอธิบายที่ดีอยู่ในลิงค์นี้

DebanjanB Aug 17 2020 at 15:18

ต้องการแยกZestimateคือZestimate®: $4,232,581คุณจะต้องทำให้เกิดWebDriverWaitสำหรับelement_to_be_clickable()และคุณสามารถใช้อย่างใดอย่างหนึ่งดังต่อไปนี้กลยุทธ์ส :

  • ใช้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