简体   繁体   中英

Python Selenium: Unable to fetch table content

I am trying to access this URL, here I have to fetch table under Price / Tax History section. Below is my code:

from selenium import webdriver
from selenium.webdriver.common.by import By

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from time import sleep
import os, sys
from multiprocessing import Pool
from selenium.webdriver import DesiredCapabilities
from selenium.webdriver.support.ui import WebDriverWait

driver = webdriver.Firefox()
wait = WebDriverWait(driver, 5)
driver.maximize_window()
driver.get('https://www.zillow.com/homedetails/2114-Bigelow-Ave-N-Seattle-WA-98109/48749425_zpid/')
sleep(10)
p_history = driver.find_elements_by_css_selector('#tax-price-history  table tr > td')
    for p in p_history:
        print(p.text)

it is not printing text.

Update Screen of the section required:

在此处输入图片说明

Update#2

Ran against PhantomJS and here you can see loader image in the section(Scroll the image)

在此处输入图片说明

You need to tell selenium to use WebDriverWait and expected_conditions to find the element once it's loaded.

You need a reference to an element that doesn't exist on page load, but should be there once the Ajax request is complete. It looks like #tax-price-history table should fulfil that requirement.

try:

from selenium.webdriver.support import expected_conditions as EC
parent = wait.until(EC.presence_of_element_located((
    By.CSS_SELECTOR, '#tax-price-history table')))

p_history = parent.find_element_by_css_selector('td')

If the element isn't found in the time limit specified in wait you'll get an error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM