1.5 KiB
Requests
Requests is a crucially important library in python that will be used very often for anything that requires acquiring data or communicating with another interface for your necessary functions.
The standard Python HTTP libraries can be difficultto use and may require bulky lines of code and hence, requests was born.
Unlike other HTTP libraries, the Requests library simplifies the process of making such requests by reducing the lines of code, in effect making the code easier to understand and debug without impacting its effectiveness. The library can be installed from within the terminal using the pip command:
pip install requests
Requests library provides easy methods for sending HTTP GET and POST requests. For example, the function to send an HTTP Get request is aptly named get():
import requests response = requests.get("https://oxylabs.io/”) print(response.text)
And the way to output if a form needs to be posted is easily done using t he post() method. The following shows how form data can be sent as a dictionary:
form_data = {'key1': 'value1', 'key2': 'value2'} response = requests.post("https://oxylabs.io/ ", data=form_data) print(response.text)
However, this library is limited in that it does not parse the extracted HTML data, ie doesn't convert data into a more readable form for analyiss.
It also cannot scrape websites written purely in JavaScript.