pythoncookiespython-3.xhttplib2

Python create cookies and then load a page with the cookies



I would like to access a web page from a python program. I have to set up cookies to load the page.
I used the httplib2 library, but I didn't find how add my own cookie

resp_headers, content = h.request("http://www.theURL.com", "GET")

How can I create cookies with the right name and value, add it to the function and then load the page?
Thanks


Solution

  • http = httplib2.Http()
    # get cookie_value here
    headers = {'Cookie':cookie_value}
    response, content = http.request("http://www.theURL.com", 'GET', headers=headers)
    

    You may want to add another header parameters to specify another HTTP request parameters.