How to find broken links in Selenium + Python

前端 未结 3 1241
再見小時候
再見小時候 2021-01-03 06:11

I\'m trying to find a broken link in Selenium and Python but getting an error in the code:

import requests
from selenium import webdriver

chrome_driver_path         


        
3条回答
  •  鱼传尺愫
    2021-01-03 06:45

    from selenium import webdriver
    chrome_driver_path = "D:\\drivers\\chromedriver.exe"
    driver=webdriver.Chrome(chrome_driver_path)
    import requests
    for link in links:
        r = requests.head(link)
        if r.status_code!=404:
             driver.get(link)
        else:
              print(str(link) + " isn't available.")
    

提交回复
热议问题