In Python, we obtain information from sources on the internet through web requests and responses. We send a request to a URL/IP address, and receive a response from the server.
Reference: HTTP request methods [MDN]
Although there are many types of requests that we can send, GET
and POST
are the two most commonly used.
Reference: HTTP response status codes [MDN]
A response from the server includes a status code indicating the success or failure of a response. This should be checked in the code and appropriately handled.
The requests
library in Python makes it easy to send HTTP requests. See the Quickstart page for some usage examples.
Many web APIs use JSON as a data exchange format, which Python ahs native support for.
For websites that do not have a web API, the response data is most likely in HTML format, which can be parsed with libraries like html.parser (built-in) or beautifulsoup.