How to enter data in the form and go to the next page with cookie in python
<p>I would like to enter data in a form and login in the website, and then download the source of the current page.
With curl from the terminal I do the following commands:</p>

<pre><code>curl -c cookie.txt --data "email=my@email.com&amp;pass=MyPass&amp;submit=login" https://mywebsite.com/pageA

curl -b cookie.txt https://mywebsite.com/pageB&gt; down.txt
</code></pre>

<p>How i can do the same with pycurl?</p>

<p>Building up from the example in <a href="http://pycurl.io/docs/latest/quickstart.html#sending-form-data" rel="nofollow">docs</a>:</p>

<pre><code>from __future__ import print_function
import pycurl
try:
    # python 3
    from urllib.parse import urlencode
except ImportError:
    # python 2
    from urllib import urlencode

c = pycurl.Curl()
c.setopt(c.URL, 'https://mywebsite.com/pageA')

post_data = {'email': 'my@email.com', 'pass': 'MyPass', 'submit': 'login'}
# Form data must be provided already urlencoded.
postfields = urlencode(post_data)
# Sets request method to POST,
# Content-Type header to application/x-www-form-urlencoded
# and data to send in request body.
c.setopt(c.POSTFIELDS, postfields)
c.setopt(c.COOKIEJAR, 'cookie.txt')
c.setopt(c.COOKIEFILE, 'cookie.txt')

try:
    c.perform()
    c.setopt(c.URL, 'https://mywebsite.com/pageB')
    c.perform()

except pycurl.error as error:
    errno, errstr = error
    print('An error occurred: ', errstr)

c.close()
</code></pre>

python curl cookies pycurl