我知道有不少人问这样一个类似的问题,但看着虽然答案,下面这个提示我不能让这个脚本工作后...Python和机械化登录到网页大学
这是我的问题...我正在尝试使用“机械化”模块来登录我的大学“膳食平衡”页面,并获取页面的源html,显示我食物的余额不断下降,然后我会解析HTML源代码,并获得数...
问题正在访问的网页说,并登录...
这个我S中的登录网站:http://www.wcu.edu/11407.asp 迎你会看到我需要填写表格结束...
这里是我试图以用于登录并与我的余额递减获得页面的代码:
import mechanize, cookielib
from time import sleep
url = 'http://www.wcu.edu/11407.asp'
myId = 'xxxxxxxx'
myPin = 'xxxxxxxx'
# Browser
#br = mechanize.Browser()
#br = mechanize.Browser(factory=mechanize.DefaultFactory(i_want_broken_xhtml_support=True))
br = mechanize.Browser(factory=mechanize.RobustFactory()) # Use this because of bad html
# Cookie Jar
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
# Browser options
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)
# Follows refresh 0 but not hangs on refresh > 0
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
# User-Agent (fake agent to google-chrome linux x86_64)
br.addheaders = [('User-agent','Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.56 Safari/535.11'),
('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'),
('Accept-Encoding', 'gzip,deflate,sdch'),
('Accept-Language', 'en-US,en;q=0.8'),
('Accept-Charset', 'ISO-8859-1,utf-8;q=0.7,*;q=0.3')]
# The site we will navigate into, handling it's session
br.open(url)
for f in br.forms():
print f
# Select the third (index two) form
br.select_form(nr=2)
# User credentials
br.form['id'] = myId
br.form['PIN'] = myPin
br.form.action = 'https://itapp.wcu.edu/BanAuthRedirector/Default.aspx
# Login
res = br.submit().read()
sleep(10)
f = file('mycatpage.html', 'w')
f.write(res)
f.close()
这给了我登录页面回来,而不是页面后....为什么?
错误源于提交,这正是问题,它在其他网站上正常工作...这就是为什么我发布这个,也许有人可以找到我错过的东西.... – Perun 2012-04-06 18:52:10