无法使用mechanize登录coursera

时间:2014-01-26 10:22:32

标签: python web-scraping mechanize

我编写了这个用于登录Coursera的Python脚本,以便我可以从我注册的其中一个课程中下载所有讲座视频。但是当我运行脚本时,我收到此错误

mechanize._mechanize.FormNotFoundError: no form matching nr 0

以下是我的脚本代码:

import mechanize

br=mechanize.Browser()
br.set_handle_robots(False)
br.open('https://class.coursera.org/inforisk-004/auth/auth_redirector?type=login&subtype=normal&email=')
br.select_form(nr=0) 
br.form["email"] = 'myemail'
br.form["password"] = 'mypassword'
br.submit()

而不是

br.select_form(nr=0)

我也试过

br.select_form(predicate=lambda f: 'class' in f.attrs and 
               f.attrs['class'] == 'coursera-signin-form')

然后我收到错误

mechanize._mechanize.FormNotFoundError: no form matching predicate <function <lambda> at 0x1b29758>

0 个答案:

没有答案