coding
파이썬 독학 5일차 pypi, requests 사용법
다아는사람
2022. 9. 5. 00:00
728x90
반응형
SMALL
앞서 살펴본 것처럼
파이썬엔 기본으로 내장되어있는 함수외에
개발자들이 만든 다양한 기능들을 import하여 사용할 수 있다.
파이피, 피즈샵이라고도 불리는 파이썬 공식 패키지 인덱스에서 많은 기능들을 확인해 볼 수 있다.
22년 9월기준 39만개의 프로젝트가 올라가 있다.
PyPI · The Python Package Index
The Python Package Index (PyPI) is a repository of software for the Python programming language.
pypi.org
오늘 살펴볼 requests 2.28.1은 한달에 무려
2억 3천만번넘게 다운로드 되고 있다.
이를 사용하기 위해 몇가지 조치가 필요하다.
대충 패키지 모양 아이콘을 눌러서
requests를 검색 후 인스톨 해준 뒤,
이제 requests가 다운로드 되었으므로
from requests를 통해 다양한 함수를 import 가능하게 되었다.
이를 이용해 만들어 본 웹사이트의 현재 상태를 표시해주는 코드.
from requests import get
#websites tuples
websites = (
"https://google.com",
"https://naver.com",
"tv07.avsee.in"
)
results = {
}
#websites안에서 각 item에 대하여 for 함수를 실행
for website in websites:
if not website.startswith("https://"):
website = f"https://{website}"
response = get(website)
if(response.status_code) == 200:
#print(f"{website} is OK")
results[website] = "OK"
elif(response.status_code >= 300 and response.status_code<400 ):
results[website] = "OK"
else:
#print(f"{website} is not OK")
results[website] = "FAILED"
print(results)
PyPI · The Python Package Index
The Python Package Index (PyPI) is a repository of software for the Python programming language.
pypi.org
728x90
반응형
LIST