简体   繁体   中英

Using pycurl to login and retrieve cookie

I found something similar to something I want to do using urllib2 here: How to use Python to login to a webpage and retrieve cookies for later usage?

Their solution was :

import urllib, urllib2, cookielib

username = 'myuser'
password = 'mypassword'

cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
login_data = urllib.urlencode({'username' : username, 'j_password' : password})
opener.open('http://www.example.com/login.php', login_data)
resp = opener.open('http://www.example.com/hiddenpage.php')
print resp.read()

I want something like this using pycurl if possible. Any assistance would be appreciated.

This looks a lot like a dupe of Logging in and using cookies in pycurl . You give pycurl a path to a file to write cookies to with

c.setopt(pycurl.COOKIEJAR, 'cookie.txt')

and a path to read them from (probably the same) with

c.setopt(pycurl.COOKIEFILE, 'cookie.txt')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM