Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-page login, can't find the form of the second page. #55

Open
ronin1770 opened this issue Feb 26, 2020 · 4 comments
Open

Multi-page login, can't find the form of the second page. #55

ronin1770 opened this issue Feb 26, 2020 · 4 comments

Comments

@ronin1770
Copy link

Mechanize Browser object is unable to find form on the second page of the login process. Internal data structure of the browser object seems to hold information about the original form.

Here are the chain of events in the multi-stage login process:

  1. User submits his username / password on the first page (let's call it P1)
  2. This information is validated by the website and user is redirected to the second page (let's call it P2)
  3. On P2 user is required to submit answer to the security question.
  4. However, when user tries to find the form / control for the security answer, Mechanize complains the form /control is not found.
  5. If response.text is printed for P2 - it displays the HTML of the P2 correctly

Sample code is shown below:

browser = mechanize.Browser(history=None)

browser.open(LOGIN_URL)
browser.select_form(nr = 0)
browser.form['username'] = UID
browser.form['userpass'] = PWD
resp = browser.submit()

security_url =  resp.geturl()

print( "The security url is: " + str(security_url) )

resp1 = browser.follow_link(security_url)
forms =  list(browser.forms())

for i in range(len(forms)):
    print( forms[i].name )
@kovidgoyal
Copy link
Contributor

You will need to provide a minimal example where this fails.

@ronin1770
Copy link
Author

ronin1770 commented Feb 27, 2020


browser = mechanize.Browser(history=None)

browser.open(LOGIN_URL)
browser.select_form(nr = 0)
browser.form['username'] = UID
browser.form['userpass'] = PWD
resp = browser.submit()

security_url =  resp.geturl()

print( "The security url is: " + str(security_url) )     #Security URL is security challenge URL

resp1 = browser.follow_link(security_url)              #Response correctly shows HTML from challenge URL page 
forms =  list(browser.forms())

for i in range(len(forms)):
    print( forms[i].name )  #Form[0] -  must contain a control called 'verify' it doesn't


browser.select_form(    nr = 0)
browser.form['verify'] = SECRET
resp = browser.submit()

print( resp.getcode() )
print( resp.read() )

@kovidgoyal
Copy link
Contributor

That's useless without LOGIN_URL and SECRET

@Karmabecu
Copy link

The Login url is https://m.facebook.com/profile.php?id=100002233045625&tsid=0.48424488103504615&source=result
Can you help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants