亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

訪問標簽內的屬性

訪問標簽內的屬性

慕的地8271018 2023-07-11 13:43:57
我的目標是訪問鏈接列表(位于"event?id=85042")。<tr class="gvrow"> == $0  <td>...</td>  <td>    <a href="event?id=85042"                                text                              </a>  </td>  ...這也會重復,所以我想獲取位于 event?id=... 中的鏈接列表,我已經從這個問題Python Selenium - get href value嘗試過這種方法,但它返回一個充滿 None 的列表primary_links = driver.find_elements_by_class_name('gvrow')links = [elem.get_attribute('href') for elem in primary_links]print(links)輸出:[None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None]期望的輸出:['https://www.iccf.com/event?id=85042', 'https://www.iccf.com/event?id=79897', 'https://www.iccf.com/event?id=66745', ...]那我該怎么辦呢?這是 html 的更好表示 
查看完整描述

1 回答

?
湖上湖

TA貢獻2003條經驗 獲得超2個贊

通過以下代碼行,您將獲得一個包含該<td>元素和任何其他具有以下元素的列表class=gvrow

driver.find_elements_by_class_name('gvrow')

顯然,<td>您返回的元素沒有該href屬性。

除了您的方法之外,您還可以使用另一種方法來獲取鏈接:

a_elements = driver.find_elements_by_xpath("//tr[@class='gvrow']/td/a")
links = [a_element.get_attribute('href') for a_element in a_elements]


查看完整回答
反對 回復 2023-07-11
  • 1 回答
  • 0 關注
  • 122 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號