简体   繁体   English

如何使用Selenium Python查找网页中的链接总数

[英]How to find the total number of links in webpage using selenium python

I already tried in Java 我已经尝试过用Java

int elementsCount = allElements.size(); 

.size() are used in Java .size()在Java中使用

Is there any options in Python, Rather than using FORLOOP. Python中有任何选项,而不是使用FORLOOP。

You can use the len() in Python 您可以在Python中使用len()

allElements = driver.find_elements_by_tag_name("a")
elementsCount = len(allElements)
print(elementsCount)

You should use find_elements_by_tag_name this gives you a list of all the elements with a tag. 您应该使用find_elements_by_tag_name这将为您提供a标签的所有元素的列表。

if you use find_element_by_tag_name you just get the first one. 如果使用find_element_by_tag_name ,则只会得到第一个。

Like this: 像这样:

total = driver.find_elements_by_tag_name("a") 
print(len(total))

Hope this helps you! 希望这对您有所帮助!

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

相关问题 使用Python查找并列出网页中的特定链接 - Find and list specific links in a webpage using Python 使用Python中的Selenium从网页中的表格中提取序列中的链接 - Extracting links in a sequence from a table in a webpage using Selenium in Python 使用 selenium python 访问网页上的所有链接和子链接 - visit all links and sublinks on webpage using selenium python 如何在python中使用selenium webdriver从网页中提取Total Confirmed的信息 - How to extract the information of Total Confirmed from webpage with selenium webdriver in python 无法在python中使用硒找到链接? - Unable to find links using selenium in python? 当页面源也包含'type'作为字符串时,使用Selenium Python查找网页上的复选框数量 - Find number of check-boxes on webpage, when page source contains 'type' as a string also, using selenium python 如何使用 selenium 从网页获取所有链接? - How to get all links from a webpage using selenium? 如何使用Selenium和python下载HTML网页? - How to download a HTML webpage using Selenium with python? 如何使用Python Selenium下载完整的网页 - How to download complete webpage using Python Selenium 如何使用 Selenium 和 python 下载 MHTML 网页? - How to download a MHTML webpage using Selenium with python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM