简体   繁体   English

Python:使用Selenium查找所有特定标签

[英]Python: find all certain tag by using selenium

HTML: HTML:

<div id="searchResult">
  <div class="buySearchResultContent">
    <div class="buySearchResultContentImg">
      <a href="carinfo-333285.php">
        <img src="carpics/9400180056/290x200/20180305101502854_4567823.jpg" srcset="carpics/9400180056/290x200/20180305101502854_9098765.jpg 290w, carpics/9400180056/435x300/20180305101502854_00000.jpg 435w , carpics/9400180056/720x520/20180305101502854_00001.jpg 720w" sizes="(min-width: 992px) 75vw, 90vw" alt="auto">
       </a>
     </div>
     <div class="buySearchResultContentImg">
       <a href="carinfo-333286.php">
         <img src="carpics/9400180056/290x200/20180305101502854_4567824.jpg" srcset="carpics/9400180056/290x200/20180305101502854_9098766.jpg 290w, carpics/9400180056/435x300/20180305101502854_00000.jpg 436w , carpics/9400180056/720x520/20180305101502854_00001.jpg 721w" sizes="(min-width: 992px) 75vw, 90vw" alt="auto">
        </a>
      </div>
    </div>
</div>

What I am trying to do is extract two hrefs, but with my code, I can only extract the first one. 我想做的是提取两个href,但是用我的代码,我只能提取第一个。

Code: 码:

driver.find_element_by_css_selector("buySearchResultContentImg > div").get_attribute("href")

尝试下面的代码以获取@href值列表:

links = [link.get_attribute("href") for link in driver.find_elements_by_css_selector(".buySearchResultContentImg>a")]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Selenium + Python中使用CSS选择器选择特定标记之上的所有类? - How to select all class that is above certain tag using CSS Selector in Selenium + Python? 使用Selenium和Python查找具有特定文本的元素 - Find element with certain text using Selenium with Python 使用Selenium Python查找下一个标签 - Find next tag using Selenium Python 使用bs4 python查找带有某些子标签的标签 - Find tag with certain child tag using bs4 python Python BeautifulSoup在某种标签类型下查找所有标签 - Python BeautifulSoup find all tags under a certain type of tag 如何使用 Python Selenium 在网站上找到某个文本? - How do you find a Certain Text on a Website using Python Selenium? Scraping - 如何在python中使用selenium查找webelement的标签 - Scraping - How to find tag of a webelement using selenium in python 如何<a>通过Python使用Selenium</a>从<a>标记中</a>提取所有文本 - How to extract all the texts from <a> tag using Selenium through Python 如何使用Selenium Webdriver(Python)验证另一个HTML标签中是否存在某个HTML标签? - How can I verify the presence of a certain HTML tag within another HTML tag using Selenium Webdriver (Python)? 从DOM获取所有链接,但从某个div标签selenium python除外 - Get all links from DOM except from a certain div tag selenium python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM