Search code examples
python-2.7httpdownloadrequesturllib2

How to make a request to get minimum data from server?


I want to make a HTTP request, so that I get minimum data from the server. For eg : If the user device is a mobile, the server will send less data.

I was doing this in python ::

req = urllib2.Request(__url, headers={'User-Agent' : "Magic Browser"})
html = urllib2.urlopen(req).read()

But it still takes some time to download all this. If it helps this is the domain from which I want to download pages : https://in.bookmyshow.com

Is there any other way so that I can download a page, quickly with minimum data? Is it even possible?


Solution

  • you can use request for upload files get datas example for get cookies:

    import requests
    
    r = requests.get('https://in.bookmyshow.com')
    print r.cookies.get_dict()
    

    or for upload file:

    import requests
    
    file = {'file':('filename.txt', open('filename.txt', 'r'), multipart/from-data)}
    data = {
          "ButtonValueNameInHtml" : "Submit",
    }
    r = requests.post('https://in.bookmyshow.com', files=file, data=data)
    

    replace in.bookmyshow.com by your own url

    you can do many Thigs With requests