How to find how many urls are working from a list of urls

Viewed 115

I have a list if URLs and using selenium I want to validate that if the URLs is not bad(opening or not). All the URLs are of different type and don't share a common feature so I can't use

(WebDriverWait)

Please don't mark this question as duplicate I have already done searches but most of them show the same way of using webdriverwait to point to a specific element and catch timeout exception. As I already said that each URL is different and they don't share common element so I think I can't use webdriverwait to point to a specific element.

If you have any other solution than python and selenium you are welcome to share.

1 Answers

Using urllib to ping would be an alternative. Run the below for each URL in the list. This function checks if you get back a valid 200 response. Adapt it for your specific needs.

def server_online(hostname): 
    """Returns True if host responds to a ping request, else False"""
    try:
        resp = urllib.request.urlopen(hostname)
        if resp.getcode() == 200: 
            return True 
    except:   
        return False 
    return False
Related