-
Notifications
You must be signed in to change notification settings - Fork 0
/
requests_map_user-agent.py
33 lines (27 loc) · 1.12 KB
/
requests_map_user-agent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests
# urls = ["https://elt.oup.com/", "https://www.w3schools.com/", "https://pynative.com/python/basics/"]
#
# headers = {
# "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
# }
#
# responses = []
#
# for url in urls:
# response = requests.get(url, headers=headers)
# responses.append(response)
#
# for url, response in zip(urls, responses):
# print(f"URL: {url}, Status code: {response.status_code}")
#
# print("responses:", responses)
print(".............................zfunkcja map")
urls = ["https://elt.oup.com/", "https://www.w3schools.com/", "https://pynative.com/python/basics/"]
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3"
}
# Użycie funkcji map do wykonania wielu żądań na raz
responses = list(map(lambda url: requests.get(url, headers=headers), urls))
# Drukowanie statusu odpowiedzi dla każdego URL-a
for url, response in zip(urls, responses):
print(f"URL: {url}, Status code: {response.status_code}")