Application for login on another site (Facebook), error "Invalidsubmiterror"

Asked

Viewed 106 times

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 I can’t fix 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
  • Possible duplicate of Login to facebook com python

  • @prmottajr, I answered that, but in fact it needed to be updated, and the parser should be passed in this case

1 answer

1


Place the parameter submit with the corresponding button:

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

Thus remaining:

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

  • I even installed an earlier version of Python to try to solve it, but it didn’t help. With your help it has improved, but there is still an error to be solved. It completes reading of the code, but still carries Beautifulsoup-related error:

  • @Scienceandsociety But have you logged in? That’s just a Warning

  • @Scienceandsociety, I think robobrowser itself is importing beautifulsoup badly. update that package or uninstall and install another

  • Yes, the login was done. This error still bothers. I already upgraded the package, but it doesn’t work. In the error itself, it says to exchange Beautifulsoup(YOUR_MARKUP}) for Beautifulsoup(YOUR_MARKUP, "html.parser") in the file "C: Python34 lib site-Packages bs4_init_.py", the problem is that in the indicated line it does not have this "Beautifulsoup(YOUR_MARKUP})"

  • I edited the @Scienceandsociety reply, with a possible solution: robobrowser.RoboBrowser(history=True, parser='html.parser')

  • Thanks Miguel! It worked perfectly! I thought this edition had to be done in the library archive. Thank you!

  • @Scienceandsociety of nothing, I also did not know, I had to go see the Docs

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.