Sunday, November 17, 2024
Google search engine
HomeLanguagesCount total number of Links In Webpage Using Selenium In Python

Count total number of Links In Webpage Using Selenium In Python

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:

  • Import required modules

Python3




# import modules 
from selenium import webdriver 
from selenium.webdriver.common.by import By 
import time


Python3




# assign web page url 


  • using By.TAG_NAME find web link in webpage.

Implementation:

Python3




#import module
from selenium import webdriver
from selenium.webdriver.common.by import By
  
  
driver = webdriver.Chrome()
  
# url
  
# find web links
link = driver.find_elements(By.TAG_NAME, 'a')
  
# using len function count how many links
print(len(link))


Output:

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments