Skip to content

Python Script Details

Anthony Pinto edited this page Apr 13, 2023 · 1 revision

This Python script imports the csv, requests, urllib3, and datetime modules. It reads a list of URLs from a file named WebURLs.txt, sends an HTTP GET request to each URL with SSL validation disabled, and records the response headers and status code in a CSV file named URL_Header_Checker_Export_<current_datetime>.csv.

Here is a step-by-step explanation of what the script does:

  1. The script disables SSL certificate verification warnings using the urllib3.disable_warnings() method.
  2. It generates the current date and time in the format "%Y%m%d_%H%M%S" using the datetime.datetime.now().strftime() method and stores it in the date variable.
  3. It defines the paths for the input and output files.
  4. It opens the input file WebURLs.txt in read mode and the output file in write mode using the with open() as statement. It also creates a CSV writer object using the csv.writer() method and writes the headers for the CSV file.
  5. The script iterates through each URL in the input file using a for loop.
  6. It cleans up the URL by stripping any leading or trailing white spaces using the strip() method.
  7. It makes an HTTP GET request to the URL with SSL validation disabled using the requests.get() method and stores the response object in the response variable.
  8. It extracts the relevant response headers and status code from the response.headers and response.status_code attributes respectively, and stores them in separate variables.
  9. It writes the URL, status code, response headers, and other attributes to the output CSV file using the csv_writer.writerow() method.
  10. If an exception occurs while making the HTTP GET request, the script writes the URL and error message to the output CSV file.

Overall, this script is useful for checking the response headers and status codes of a list of URLs and recording them in a CSV file for further analysis.

Clone this wiki locally