Count total number of Links In Webpage Using Selenium In Python
Last Updated :
04 Jan, 2021
Selenium is a powerful tool for controlling web browsers through programs and performing browser automation. It is functional for all browsers, works on all major OS and its scripts are written in various languages i.e Python, Java, C#, etc, we will be working with Python.
Installation
1.1 Selenium Bindings in Python
Selenium Python bindings provide a convenient API to access Selenium Web Driver like Firefox,Chrome,etc.
Pip install Selenium
1.2 Web Drivers
Selenium requires a web driver to interface with the chosen browser. Web drivers is a package to interact with a web browser. It interacts with the web browser or a remote web server through a wire protocol which is common to all. You can check out and install the web drivers of your browser choice.
Chrome: https://sites.google.com/a/chromium.org/chromedriver/downloads
Firefox: https://github.com/mozilla/geckodriver/releases
Safari: https://webkit.org/blog/6900/webdriver-support-in-safari-10/
Step-by-step Approach:
Python3
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
|
- using By.TAG_NAME find web link in webpage.
Implementation:
Python3
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
link = driver.find_elements(By.TAG_NAME, 'a' )
print ( len (link))
|
Output:
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...