title: Help with Python: login into website
body: <p>I'm trying to connect to a website with Python, but I don't know how to do that.</p>
  
  <p>The HTML of the website looks like that :</p>
  
  <pre><code>&lt;form action="connexion.php" method="post"&gt;
    User&lt;br /&gt;
    &lt;input name="login_user" type="text" /&gt;
    &lt;br /&gt;
    Password&lt;br /&gt;
    &lt;input name="pass_word" type="password" /&gt;
    &lt;br /&gt;
    &lt;input value="Connexion" type="submit" /&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Ok, I will try to explain better ...</p>
  
  <p>Here is the script to connect to a pun_bb forum :</p>
  
  <pre><code>import urllib
  import string
  
  host = "http://punbbforum.example.com"
  username = "userxxx"
  password = "passwww"
  params = {
      'req_username' : username,
      'req_password' : password,
      'form_sent' : 1
      }
  
  wclient = urllib.URLopener()
  
  req = wclient.open(host + "/login.php?action=in", urllib.urlencode(params))
  info = req.info()
  
  if 'set-cookie' not in info:
      sys.exit(-3)
  
  cookie = info['set-cookie']
  
  cookie = cookie[:string.find(cookie, ';')]
  wclient.addheader('Cookie', cookie);
  
  req = wclient.open("http://punbbforum.example.com/post.php?fid=15")
  print req.read()
  </code></pre>
  
  <p>But it works only with punbb websites ... I would like to create a script who it will work with this example ...</p>
  
  <p>Thanks</p>