Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in Python by (12.7k points)
recategorized by

I'm getting an error when I tried to find a broken link in Python and Selenium.

import requests

from selenium import webdriver

chrome_driver_path = "D:\\drivers\\chromedriver.exe"



links = driver.find_elements_by_css_selector("a")

images = driver.find_elements_by_css_selector("img")

for link in links:

    r = requests.head(link.get_attribute('href')

    print(r.status_code == 200)


raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='', port=443): Max retries exceeded with url: /?utm_source=OGB&utm_medium=app (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:777)'),))

Another exception arose while handling the above exception:

self._sslobj.do_handshake() ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:777)

Traceback (most recent call last):

1 Answer

0 votes
by (26.4k points)

Use the following code, To find the status of the links on the page


import requests

from selenium import webdriver

options = webdriver.ChromeOptions() 



driver=webdriver.Chrome(chrome_options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')


links = driver.find_elements_by_css_selector("a")

for link in links:

    r = requests.head(link.get_attribute('href'))

    print(link.get_attribute('href'), r.status_code)

Output: 302 200 301 302 200 302 200 302 301 302 302 302 302 302 200 302 301 302 200 405 302 302 200 301 200 200

Want to learn more about Python concepts? Come and Join: Python course

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers


94.1k users

Browse Categories