-3

For this code:

import mechanize
br = mechanize.Browser()
br.set_handle_robots(False)
br.open("https://www.facebook.com/login/identify?ctx=recover")
for i in bt.forms():
    print i

the result is:

<POST https://www.facebook.com/login.php?login_attempt=1 application/x-www-form-urlencoded
  <HiddenControl(lsd=AVrIS_yx) (readonly)>
  <TextControl(email=)>
  <PasswordControl(pass=)>
  <SubmitControl(<None>=طھط³ط¬ظٹظ„ ط§ظ„ط¯ط®ظˆظ„) (readonly)>
  <CheckboxControl(persistent=[1])>
  <HiddenControl(default_persistent=0) (readonly)>
  <HiddenControl(timezone=) (readonly)>
  <HiddenControl(lgnrnd=004018_suds) (readonly)>
  <HiddenControl(lgnjs=n) (readonly)>
  <HiddenControl(locale=ar_AR) (readonly)>
  <HiddenControl(next=https://www.facebook.com/login/identify?ctx=recover) (readonly)>>
<POST https://www.facebook.com/ajax/login/help/identify.php?ctx=recover application/x-www-form-urlencoded
  <HiddenControl(lsd=AVrIS_yx) (readonly)>
  <TextControl(email=)>
  <SubmitControl(did_submit=ط¨ط­ط«) (readonly)>>

How can I select the second post, which has only one parameter (email), and submit it?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 1
    You may get more answers if you turn the title into a question - ie : How can I select a form with python-mechanize? Also - both to encourage more answers, and to assist yourself in finding the problem - try reducing to a simpler one - create the simplest html page with examples of the structure you would like to navigate. – Danny Staple Jan 16 '15 at 09:44

2 Answers2

0

Select it using select_form():

br.select_form(nr=1)
br.form['email'] = 'email here'
req = br.submit()

Important note: be careful not to violate Facebook Web-scraping Terms.

alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
0

when i do this

br.select_form(nr=1)
br.form['email'] = 'email'
br.submit()
br.response().read()

the response is be empty