Python td数据的Web抓取

Python td数据的Web抓取,python,selenium,selenium-webdriver,web-scraping,Python,Selenium,Selenium Webdriver,Web Scraping,有人能给我解释一下为什么我的代码没有接收到PriorSettle td?我得到了几个月的时间,但无论出于什么原因,普里奥塞特专栏没有出现 lc_result={} url = "http://www.cmegroup.com/trading/agricultural/livestock/live-cattle.html" driver = webdriver.Chrome() driver.set_window_size(2,2) driver.get(url) #this will go

有人能给我解释一下为什么我的代码没有接收到PriorSettle td?我得到了几个月的时间,但无论出于什么原因,普里奥塞特专栏没有出现

lc_result={}

url = "http://www.cmegroup.com/trading/agricultural/livestock/live-cattle.html"

driver = webdriver.Chrome() 
driver.set_window_size(2,2)
driver.get(url) #this will go the the actual url listed
print('     Live Cattle Futures'+localtime.center(50))
table = driver.find_element_by_id('quotesFuturesProductTable1')
for row in table.find_elements_by_tag_name('tr')[2:]:
    month=row.find_elements_by_tag_name('td')[0].text  
    priorsettle=row.find_elements_by_tag_name('td')[4].text

    print month, priorsettle
    lc_result[month]=[priorsettle]

driver.close()
print(str(date.today()))

您需要等待加载表。只需添加一个延迟就可以让它对我起作用:

driver.get(url)

time.sleep(3)

table = driver.find_element_by_id('quotesFuturesProductTable1')
...
印刷品:

DEC 2014 168.025
FEB 2015 166.900
APR 2015 164.775
JUN 2015 154.800
AUG 2015 152.900
OCT 2015 154.100
DEC 2015 154.250
FEB 2016 153.850
APR 2016 0.000
仅供参考,使用
time.sleep()
的隐式超时不是一种可靠且推荐的等待元素的方法
Selenium
具有内置机制