簡體   English   中英

硒如何從屬性中提取href

[英]Selenium how to extract href from attributes

<div class="turbolink_scroller" id="container">
 <article><div class="inner- article">
  <a style="height:81px;" href="LINK TO EXTRACT">
   <img width="81" height="81" src="//image.jpg" alt="code" />

你好! 我對硒很陌生,我一直在研究如何獲取Webdriver的資源。 到目前為止,我正在嘗試使用上述的alt代碼提取href鏈接,但不確定文檔是否可以執行此操作。 我感覺答案是find_by_xpath,但我不確定。 謝謝您的提示!

方式如下

href = driver.find_element_by_tag_name('a').get_attribute('href')

當然,您的頁面中可能會有很多“ a”標簽,因此您可能會找到相應標簽的路徑,

例如

div = driver.find_element_by_id('container')
a = div.find_element_by_tag_name('a')
href = a.get_attribute('href')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM