这将帮助您登录一个站点并下载一个页面,例如:
import mechanizebr=mechanize.Browser()br.open('http://www.yourfavoritesite.com')br.select_form(nr=0) #check yoursite forms to match the correct numberbr['Username']='Username' #use the proper input type=text namebr['Password']='Password' #use the proper input type=password namebr.submit()br.retrieve('https://www.yourfavoritesite.com/pagetoretrieve.html','yourfavoritepage.html')该脚本假定您的登录表单是页面的第一页,输入名称是
Username和
Password。
您还可以通过以下方式按名称选择表单:
br.select_form(name="thisthing")
请将此脚本调整为您喜欢的网站登录页面。
正如AlexMartelli所指出的那样,应使用一些配置参数将此脚本通用化以处理不同的站点。



