Python HTML Get Parameter

Problem Formulation: How to perform an HTTP get call in Python?

Python HTML Get Parameter Gif

Solution: Use Python’s requests library.

import requests
payload = {'param_1': 'value_1', 'param_2': 'value_2'}
r = requests.get('http://example.com/', params=payload)

This is semantically equivalent to issuing an HTTP get call:

http://example.com?param_1=value_1&param_2=value_2

In fact, you can obtain this exact URL by using the r.url attribute on the request object:

print(r.url)
# http://example.com?param_1=value_1&param_2=value_2

You can find the text response by using the r.text attribute of the request object:

print(r.text)
# [... return value from server ...]

Alternatively, if you expect a json object, you can also do:

print(r.json())
# [{... returned json object ... }]

Try it yourself in our interactive Jupyter Notebook with Google Colab:

Resources: