Python 요청 모듈
예시
웹 페이지에 요청하고 응답 텍스트를 인쇄합니다.
import requests
x = requests.get('https://w3schools.com/python/demopage.htm')
print(x.text)
정의 및 사용
requests
모듈을 사용하면 Python을 사용하여 HTTP 요청을 보낼 수 있습니다 .
HTTP 요청은 모든 응답 데이터(내용, 인코딩, 상태 등)와 함께 응답 개체 를 반환합니다.
요청 모듈 다운로드 및 설치
명령줄에서 PIP 위치로 이동하고 다음을 입력합니다.
C:\Users\Your Name\AppData\Local\Programs\Python\Python36-32\Scripts>pip install requests
통사론
requests.methodname(params)
행동 양식
Method | Description |
---|---|
delete(url, args) | Sends a DELETE request to the specified url |
get(url, params, args) | Sends a GET request to the specified url |
head(url, args) | Sends a HEAD request to the specified url |
patch(url, data, args) | Sends a PATCH request to the specified url |
post(url, data, json, args) | Sends a POST request to the specified url |
put(url, data, args) | Sends a PUT request to the specified url |
request(method, url, args) | Sends a request of the specified method to the specified url |