0

我试图使用 machanize 进入一个站点,但是当我运行我的脚本时,它仍然只是给我主页的源代码,而不是实际站点的源代码

这是代码

from mechanize import Browser

USERNAME = "my username"
PASSWORD = "my pass"
LOGIN_PAGE = "https://ps.rsd.edu/public/"

browser = Browser()
browser.open( LOGIN_PAGE )


browser.select_form( nr=0 ) 
browser['pw'] = PASSWORD
response = browser.submit()
print response.read()

请帮忙!

4

1 回答 1

1

您忘记输入用户名。它应该与密码输入相同。例子:

from mechanize import Browser

USERNAME = "my username"
PASSWORD = "my pass"
LOGIN_PAGE = "https://ps.rsd.edu/public/"

browser = Browser()
browser.open( LOGIN_PAGE )


browser.select_form( nr=0 ) 
browser['account'] = USERNAME
browser['pw'] = PASSWORD
response = browser.submit()
print response.read()
于 2013-04-17T15:40:23.033 回答