0% found this document useful (0 votes)
10 views2 pages

Python Script

The document contains a Python script that checks the status of URLs to determine if they are working. It defines a function to make HTTP requests and handle exceptions, then tests a predefined list of URLs as well as URLs read from a file. The results of the status checks are printed to the console.

Uploaded by

Banu M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Python Script

The document contains a Python script that checks the status of URLs to determine if they are working. It defines a function to make HTTP requests and handle exceptions, then tests a predefined list of URLs as well as URLs read from a file. The results of the status checks are printed to the console.

Uploaded by

Banu M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

import requests

# Function to check if a URL is working

def check_url_status(url):

try:

response = requests.get(url, timeout=10)

if response.status_code == 200:

return f"URL {url} is working (Status: {response.status_code})"

else:

return f"URL {url} is not working (Status:


{response.status_code})"

except requests.exceptions.RequestException as e:

return f"URL {url} failed with exception: {e}"

# List of URLs to test

urls = [

"https://www.example.com",

"https://www.google.com",

"https://www.nonexistentwebsite.com"

# Loop through URLs and check their status

for url in urls:

print(check_url_status(url))

# Read URLs from a file

with open('urls.txt', 'r') as file:

urls = file.readlines()
# Check each URL from the file

for url in urls:

url = url.strip() # Remove any whitespace/newline characters

print(check_url_status(url))

You might also like