Application for login to another site (Facebook), error "InvalidSubmitError"

0

My code is this:

import robobrowser
import re

url = 'https://m.facebook.com'
loggedin_title = 'Facebook' # isto vai servir para confirmarmos que estamos loggedin, vendo o titulo da pagina para onde fomos redirecionados 

browser = robobrowser.RoboBrowser(history=True)
browser.open(url)

form = browser.get_form(id='login_form')
form['email'].value = 'USERNAME'
form['pass'].value = 'PASSWORD'
browser.submit_form(form)

redirect_title = re.compile('<title>(.*?)</title>').search(str(browser.parsed)).group(1)

if(redirect_title == loggedin_title):
    print('[+] SUCCESS')
    print('Username: {}\nPassword: {}'.format(form['email'].value, form['pass'].value))
else:
    print('[-] LOGIN FAILED')

But I get this error and can not solve it:

Warning (from warnings module):
  File "C:\Users\EDUARDO\AppData\Local\Programs\Python\Python36\lib\site-packages\bs4\__init__.py", line 181
    markup_type=markup_type))
UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("lxml"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 1 of the file <string>. To get rid of this warning, change code that looks like this:

 BeautifulSoup(YOUR_MARKUP})

to this:

 BeautifulSoup(YOUR_MARKUP, "lxml")

Traceback (most recent call last):
  File "C:\Users\ED\Documents\Python\Python\Python\LOGIN\login.py", line 13, in <module>
    browser.submit_form(form)
  File "C:\Users\ED\AppData\Local\Programs\Python\Python36\lib\site-packages\robobrowser\browser.py", line 339, in submit_form
    payload = form.serialize(submit=submit)
  File "C:\Users\ED\AppData\Local\Programs\Python\Python36\lib\site-packages\robobrowser\forms\form.py", line 226, in serialize
    include_fields = prepare_fields(self.fields, self.submit_fields, submit)
  File "C:\Users\ED\AppData\Local\Programs\Python\Python36\lib\site-packages\robobrowser\forms\form.py", line 154, in prepare_fields
    raise exceptions.InvalidSubmitError()
robobrowser.exceptions.InvalidSubmitError
    
asked by anonymous 16.01.2018 / 12:25

1 answer

1

Set the submit parameter with the corresponding button:

...
browser.submit_form(form, submit=form['login'])
...

Looking like this:

import robobrowser
import re

url = 'https://m.facebook.com'
loggedin_title = 'Facebook' # isto vai servir para confirmarmos que estamos loggedin, vendo o titulo da pagina para onde fomos redirecionados 

browser = robobrowser.RoboBrowser(history=True, parser='html.parser')
browser.open(url)

form = browser.get_form(id='login_form')
form['email'].value = 'USERNAME'
form['pass'].value = 'PASSWORD'
browser.submit_form(form, submit=form['login']) # <-- acresentar aqui

redirect_title = re.compile('<title>(.*?)</title>').search(str(browser.parsed)).group(1)

if(redirect_title == loggedin_title):
    print('[+] SUCCESS')
    print('Username: {}\nPassword: {}'.format(form['email'].value, form['pass'].value))
else:
    print('[-] LOGIN FAILED')

DOCS

    
16.01.2018 / 13:16