2017-08-02 26 views

回答

0

你可以這樣做

from selenium import webdriver 
import pandas as pd 
import time 

driver = webdriver.Chrome() 
driver.get('https://www.predictit.org/Contract/7422/Will-Trump-veto-Russian-sanctions-bill-by-August-31#prices') 

time.sleep(2) 
tables = pd.read_html(driver.page_source) # returns list of dataframes 
print(len(tables)) 
print(tables[2]) # this is table with YES 
print(tables[3]) # this is the table with NO 

此代碼僅取表,但你需要做一些清潔。你可以閱讀文檔pandas.DataFrame

+0

一旦我安裝了所有必要的模塊,就做到了這一點。謝謝! 我將不得不查找「數據框」究竟是什麼。 – svadhisthana

+0

爲了記錄,您必須在此解決方案運行之前點擊價格標籤。所以,「elem = driver.find_element_by_id('getPrices') elem.click()」需要在代碼中。 – svadhisthana

+0

我打開的網址包含'#價格'。所以我不需要找到任何元素。 – ksai