Python Web request

An example code to interact with a webpage with python request library.

import requests
from colorama import Fore, Back, Style
import sys

URL=sys.argv[1]

requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)

def format_text(title,item):
    cr = '\r\n'
    section_break = cr + "*" * 20 + cr
    item = str(item)
    text = Style.BRIGHT + Fore.RED + title + Fore.RESET + section_break + item + section_break
    return text;

r = requests.get(URL,verify=False)
print format_text('r.status_code is: ',r.status_code)
print format_text('r.headers is: ',r.headers)
print format_text('r.cookies is: ',r.cookies)
print format_text('r.text is: ',r.text)

Now you can actually run the script to interact with  a URL by calling the script with URL as the argument:

python request.py <url>