Advertisement
GeeckoDev

formadep

Dec 1st, 2012
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. import mechanize
  2. import cookielib
  3. from bs4 import BeautifulSoup
  4.  
  5. br = mechanize.Browser()
  6. br.set_handle_equiv(True)
  7. #br.set_handle_gzip(True)
  8. br.set_handle_redirect(True)
  9. br.set_handle_referer(True)
  10. br.set_handle_robots(False)
  11.  
  12. cj = cookielib.LWPCookieJar()
  13. br.set_cookiejar(cj)
  14.  
  15. # Follows refresh 0 but not hangs on refresh > 0
  16. br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
  17.  
  18. #br.set_debug_http(True)
  19. #br.set_debug_redirects(True)
  20. #br.set_debug_responses(True)
  21.  
  22. # User-agent
  23. br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
  24.  
  25. # Open "Formadep la Rochelle" to log in
  26. r = br.open('http://www.formadep.fr/infolarochelle')
  27. # Open "Emploi du temps par groupe"
  28. r = br.open('http://www.formadep.fr/extretud/exte_edtgroupe.aspx')
  29.  
  30. # Verify the title
  31. assert br.title() == "Extranet Alternance TC"
  32.  
  33. # Select a group and submit
  34. br.select_form("_ctl0")
  35. br["dd1"] = ["6"]  # IE
  36. br.submit()
  37.  
  38. # Get the soup
  39. br.select_form("_ctl0")
  40. text = BeautifulSoup(br.response()).get_text()
  41.  
  42. #print text
  43.  
  44. # Find the strings
  45. for line in text.split("\n"):
  46.     if ("\t\t\t" in line) and (":" in line):
  47.         print line.replace("\t\t\t", "")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement