[PYTHON] SCRAPY - fourslickz/notes GitHub Wiki

import threading
import requests

# Function to hit the URL
def hit_url(url):
    try:
        response = requests.get(url)
        print(f"URL: {url}, Status Code: {response.status_code}")
    except requests.RequestException as e:
        print(f"Error hitting URL: {url}, Error: {e}")

# Function to create and start threads
def start_threads(url, num_threads):
    threads = []
    for i in range(num_threads):
        thread = threading.Thread(target=hit_url, args=(url,))
        threads.append(thread)
        thread.start()
    
    for thread in threads:
        thread.join()

if __name__ == "__main__":
    url = "http://example.com"  # Replace with the URL you want to hit
    num_threads = 10  # Replace with the number of threads you want to use

    start_threads(url, num_threads)