Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 1st, 2012  |  syntax: None  |  size: 0.40 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to access a password protected site using python?
  2. yahoo_mail = 'http://mail.cn.yahoo.com'
  3. br = mechanize.Browser()
  4. r = br.open(yahoo_mail)
  5. print r.info()  #here, I got 200, it's ok apparently
  6.  
  7. br.select_form(nr=0)  #select the login form
  8. r = br.submit()  #submit the form without providing username and password
  9. print r.info()  #but I didn't get 401, why?
  10.        
  11. f = open('a.html', 'w')
  12. f.write(r.read())