import threading
import requests
# 请求的网址列表
urls = [
'https://www.example.com',
'https://www.google.com',
'https://www.wikipedia.org',
'https://www.github.com'
]
def fetch_url(url):
try:
response = requests.get(url)
print(f'URL: {url} - Status Code: {response.status_code}')
except requests.RequestException as e:
print(f'URL: {url} - Error: {e}')
def main():
threads = []
for url in urls:
thread = threading.Thread(target=fetch_url, args=(url,))
threads.append(thread)
thread.start()
for thread in threads:
thread.join()
if __name__ == '__main__':
main()