-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
30 lines (21 loc) · 878 Bytes
/
Copy pathmain.py
File metadata and controls
30 lines (21 loc) · 878 Bytes
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
import sys
import requests
# Адрес сайта, к которому делаем HTTP-запрос.
URL = "https://www.google.com"
def main():
# requests.get скачивает главную страницу сайта.
# timeout=10 означает: ждать ответа максимум 10 секунд.
response = requests.get(
URL,
timeout=10,
headers={"User-Agent": "Python requests learning example"},
)
# status_code - это HTTP-код ответа сервера.
# 200 означает, что запрос выполнен успешно.
print(f"URL: {URL}")
print(f"Status code: {response.status_code}")
# Если ответ не 200, завершаем программу с ошибкой.
if response.status_code != 200:
sys.exit(1)
if __name__ == "__main__":
main()