Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import mechanize
- import cookielib
- from bs4 import BeautifulSoup
- br = mechanize.Browser()
- br.set_handle_equiv(True)
- #br.set_handle_gzip(True)
- br.set_handle_redirect(True)
- br.set_handle_referer(True)
- br.set_handle_robots(False)
- cj = cookielib.LWPCookieJar()
- br.set_cookiejar(cj)
- # Follows refresh 0 but not hangs on refresh > 0
- br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
- #br.set_debug_http(True)
- #br.set_debug_redirects(True)
- #br.set_debug_responses(True)
- # User-agent
- 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')]
- # Open "Formadep la Rochelle" to log in
- r = br.open('http://www.formadep.fr/infolarochelle')
- # Open "Emploi du temps par groupe"
- r = br.open('http://www.formadep.fr/extretud/exte_edtgroupe.aspx')
- # Verify the title
- assert br.title() == "Extranet Alternance TC"
- # Select a group and submit
- br.select_form("_ctl0")
- br["dd1"] = ["6"] # IE
- br.submit()
- # Get the soup
- br.select_form("_ctl0")
- text = BeautifulSoup(br.response()).get_text()
- #print text
- # Find the strings
- for line in text.split("\n"):
- if ("\t\t\t" in line) and (":" in line):
- print line.replace("\t\t\t", "")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement