Python Requests- Modul
Beispiel
Stellen Sie eine Anfrage an eine Webseite und drucken Sie den Antworttext aus:
import requests
x = requests.get('https://w3schools.com/python/demopage.htm')
print(x.text)
Definition und Verwendung
Das requests
Modul ermöglicht es Ihnen, HTTP-Anforderungen mit Python zu senden.
Die HTTP-Anforderung gibt ein Response-Objekt mit allen Antwortdaten (Inhalt, Kodierung, Status usw.) zurück.
Laden Sie das Anforderungsmodul herunter und installieren Sie es
Navigieren Sie in Ihrer Befehlszeile zum Speicherort von PIP und geben Sie Folgendes ein:
C:\Users\Your Name\AppData\Local\Programs\Python\Python36-32\Scripts>pip install requests
Syntax
requests.methodname(params)
Methoden
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 |