Mô- đun yêu cầu Python
Ví dụ
Đưa ra yêu cầu tới một trang web và in văn bản phản hồi:
import requests
x = requests.get('https://example.com.vn/python/demopage.htm')
print(x.text)
Chạy ví dụ »Định nghĩa và cách sử dụng
Mô-đun requests
cho phép bạn gửi yêu cầu HTTP bằng Python.
Yêu cầu HTTP trả về Đối tượng phản hồi với tất cả dữ liệu phản hồi (nội dung, mã hóa, trạng thái, v.v.).
Tải xuống và cài đặt mô-đun yêu cầu
Điều hướng dòng lệnh của bạn đến vị trí của PIP và gõ như sau:
C:\Users\ Your Name \AppData\Local\Programs\Python\Python36-32\Scripts>pip install requests
Cú pháp
requests. methodname(params)
phương pháp
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 |