title: using python to login onto a .jsp webpage
body: <p>i try to access this page<code>(http://xx/login.jsp)</code> using python and do some scrapping later.</p>
  
  <pre><code>{&lt;form method = "post" name = "login" action = "llogin.jsp"&gt; 
                  &lt;input type = "text" name = "llogin" value = ""&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;&lt;td colspan = "2"&gt;&lt;b&gt;Password&lt;/b&gt;&lt;/td&gt;&lt;td width = "50px"&gt;
                  &lt;input type = "password" name = "lpasswd" value = ""&gt;&lt;/td&gt;
                  &lt;/tr&gt;
                  &lt;tr&gt;&lt;td colspan="2"&gt;&lt;/td&gt;&lt;td&gt;
                  &lt;input type = "submit" name = "submit" value = "Login"&gt;
                  &lt;input type = "reset" name = "reset" value = "Reset"&gt;&lt;/td&gt;
                  &lt;/form&gt;
                  &lt;/tr&gt;
                  }
  </code></pre>
  
  <p>the code i wrote (all borrowed from StackOverflow):</p>
  
  <pre><code>import urllib, urllib2, cookielib
  username = ''
  password = ''
  cj = cookielib.CookieJar()
  opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
  login_data = urllib.urlencode({'llogin' : username, 'lpasswd' : password})
  req=urllib2.Request('http://xx/login.jsp', login_data)
  resp=urllib2.urlopen(req)
  data =resp.read()
  print data[:]}
  </code></pre>
  
  <p>it ended up printing the login.jsp page </p>
  
  <p>the form method has an action arguement of llogin.jsp should i enter this link or login.jsp(main link) in urllib2.Request.?
  on putting llogin.jsp i got the error:</p>
  
  <pre><code>There was some error in the request and hence you have been logged out. Inconvenience is regretted. Click to &lt;a href="login.jsp"&gt;re-login&lt;/a&gt;
  </code></pre>
  
  <p>how do i handle this action field?
  page on successful access is http:/xx/shome.jsp</p>
  
  <p>how do i get access to the new page and verify that indeed my login has worked.?</p>
  
  <p>what am i doing wrong?</p>
  
  <p>is it possible to to get the newpage(which opens after login success) on a webbrowser eg firefox?(as a confirmation that it indeed worked).used webbrowser module before but how do i integrate it here?</p>
  
  <p>can this be done in "requests" module?</p>
  
  <p>there are many posts on how to access webpages through login but i couldnt find any on how to verify that you have indeed successfully done it?</p>