Python 使用mechanize的密码保护站点

Python 使用mechanize的密码保护站点,python,authentication,mechanize,mechanize-python,Python,Authentication,Mechanize,Mechanize Python,我想访问way2sms,这是一个使用mechanize的密码保护站点 import mechanize br = mechanize.Browser() br.open('http://site2.way2sms.com/content/index.html') for form in br.forms(): print form 这就是 <loginform POST http://site2.way2sms.com/content/index.html applicatio

我想访问way2sms,这是一个使用mechanize的密码保护站点

import mechanize
br = mechanize.Browser()
br.open('http://site2.way2sms.com/content/index.html')
for form in br.forms():
     print form
这就是

<loginform POST http://site2.way2sms.com/content/index.html application/x-www-form-urlencoded
<IgnoreControl(button2=<None>)>
<TextControl(username=Mobile Number)>
<PasswordControl(password=******)>
<SubmitControl(button=Login) (readonly)>>

这将在登录后提供页面的html,但如何在登录前获取页面。有人能帮忙吗?

看看页面源代码:他们在提交表单时会执行一些javascript验证,在这期间会替换表单操作,而mechanize显然不会这样做,您必须在提交表单之前手动执行该操作。

使用以下方法:

import mechanize
br = mechanize.Browser()
br.open('http://site2.way2sms.com/content/index.html')
print br.response().read()
import mechanize
br = mechanize.Browser()
br.open('http://site2.way2sms.com/content/index.html')
print br.response().read()