2017-04-06 27 views
0

保存了第二個TD文本我有一個表,我需要所有的發票號存儲在列表從每Tr

enter image description here

然後,我需要比較獨立的類似頁面。

我不知道如何解決這個問題,但是這是我迄今爲止寫的,但我不確定這是否是正確的方法。

list = [] 
table_id = self.driver.find_element(By.ID, 'tblData') 
rows = table_id.find_elements(By.TAG_NAME, "tr") # get all of the rows in the table 
for row in rows: 
    # Get the columns (all the column 2)   
    col = row.find_elements(By.TAG_NAME, "td")[1] #note: index start from 0, 1 is col 2 
    list.append(col) 
+0

保留名稱有它爲你工作至今? –

回答

2

你可以簡單地使用下面一行:

invoices = [td.text for td in driver.find_elements_by_xpath("//table[@id='tblData']//tr[1]/td")] 

另外請注意,你不應該使用list變量名,因爲它是在Python