我正试图抓住zillow网站的内容.
问题是我无法抓住价格和税收历史的内容.
我认为它们是javascript元素加载页面加载时因此尝试使用selenium但我仍然无法得到它们.
以下就是我的尝试.
码
phistory = soup.find("div",{"id": "hdp-price-history"})
print phistory
HTML
最佳答案
您可以尝试等到所需的< table>生成并变得可见:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
driver.get("https://www.zillow.com/homedetails/689-Luis-Munoz-Marin-Blvd-APT-508-Jersey-City-NJ-07310/108625724_zpid/")
table = wait(driver,10).until(EC.visibility_of_element_located((By.XPATH,'//div[@id="hdp-price-history"]//table')))
print(table.text)
输出:
DATE EVENT PRICE $/SQFT SOURCE
05/03/17 Listed for sale $750,000+159% $534 KELLER WILLIAM...
06/15/11 Sold $290,000-38.3% $206 Public Record
10/14/05 Sold $470,000 $334 Public Record
您也可以在不使用BeautifulSoup的情况下解析它,例如
print(table.find_element_by_xpath('.//td[text()="Listed for sale"]/following::span').text)
输出:
$750,000
要么
print(table.find_element_by_xpath('.//td[text()="Sold"]/following::span').text)
输出:
$290,000
原文链接:https://www.f2er.com/html/425588.html