Get request with urllib

    0

    0

    iAbdullahMughal

    python-requetsdownload-htmlget-request
    Handle Internet With Python

    Read data from webpage using **python3 buildin request ** function

    Following python code can send get request to a web page and download html document. Later this downloaded documented is printed on console.

    from urllib.request import Request, urlopen
    
    ENDPOINT_URL = "http://www.iabdullahmughal.com"
    request = Request(ENDPOINT_URL)
    USER_AGENT = "python code"
    request.add_header('Connection', 'keep-alive')
    request.add_header('Cache-Control', 'max-age=0')
    request.add_header('DNT', '1')
    request.add_header('Upgrade-Insecure-Requests', '1')
    request.add_header('Accept-Language', 'en-US,en;q=0.9')
    request.add_header('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,'
                                 'image/avif,image/webp,'
                                 'image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9')
    request.add_header('User-Agent', f'{USER_AGENT}')
    with urlopen(request) as GATEWAY:
        CONTENT = GATEWAY.read()
        print(CONTENT)
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.