我被困在一端,我無法獲得價值。
為了更好地查看...我需要獲取這些值
1)809
<td class="tdResult" id="tdResultSpFlights" onclick="consultaSpFlights(809,1);" style="cursor:pointer;"><u>809</u></td>
2)2
<td class="tdResult" id="tdResultSpCanceledFlights" onclick="consultaSpCanceledFlights(2,1);" style="cursor:pointer;"><u>2</u></td>
3)90
<td class="tdResult" id="tdResultSpDelayedFlights" onclick="consultaSpDelayedFlights(90,1);" style="cursor:pointer;"><u>90</u></td>
如果我使用
find_element(By.TAG_NAME,"u")
使用第一個是正確的,但我無法獲得其他的,因為它們具有相同的標簽名稱。我已經嘗試過使用 xpath、class 和 id。我怎樣才能得到上面的值?
uj5u.com熱心網友回復:
find_element()將回傳第一個匹配元素。相反,您需要使用find_elements()并提取可以使用串列理解的文本,如下所示:
print([my_elem.text for my_elem in driver.find_elements(By.TAG_NAME, "u")])
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/424674.html
