पायथन अनुरोध मॉड्यूल
उदाहरण
वेब पेज के लिए अनुरोध करें, और प्रतिक्रिया टेक्स्ट प्रिंट करें:
import requests
x = requests.get('https://w3schools.com/python/demopage.htm')
print(x.text)
परिभाषा और उपयोग
requests
मॉड्यूल आपको पायथन का उपयोग करके 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 |