response python code example

Example 1: python print return code of requests

>>> import requests
>>> r = requests.get('http://httpbin.org/status/404')
>>> r.status_code
404

Example 2: python send get request with headers

r=requests.get("http://www.example.com/", headers={"content-type":"text"})

Example 3: python requests get

# pip install requests
import requests
req = requests.get('<url here>', 'html.parser')
print(req.text)

Example 4: python response

# It is the response you get. It has many attributes.

import requests

response = request.get('https://abc.com')

print(response.[the response attribute])

# Some response attributes: 
response.status_code
response.json()
response.text

Tags:

Html Example