I’m trying to use mechanize in python to login to this site: https://login.haaretz.co.il/ On the surface, it looks like a 2-phase login process, same as google, but following receipts for google login via mechanize gets me nowhere. After submit()-ing the browser seems to remain on the same page, with a single form containing the single userName control. What am I doing wrong?
>>> import mechanize >>> br = mechanize.Browser() >>> br.open('https://login.haaretz.co.il/') <response_seek_wrapper at 0x7f53bfbc4a00 whose wrapped object = <closeable_response at 0x7f53bfbc4580 whose fp = <_io.BufferedReader name=3>>> >>> >>> br.select_form(nr=0) >>> >>> print(br.form) <GET https://login.haaretz.co.il/ application/x-www-form-urlencoded <TextControl(userName=)> <IgnoreControl(<None>=<None>)>> >>> br['userName']='my_email@gmail.com' >>> resp = br.submit() >>> # and after submitting I'm back a square one >>> print(br.forms()[0]) <GET https://login.haaretz.co.il/?userName=my_email%40gmail.com application/x-www-form-urlencoded <TextControl(userName=)> <IgnoreControl(<None>=<None>)>> >>>
Is this hopeless? Am I doing it wrong?
Advertisement
Answer
My guess is that the login process depends on JavaScript. If the login depends on JavaScript you won’t get the results you want with Mechanize. See Mechanize and Javascript
The script tag at xpath 'body/script[2]'
has a JavaScript object with 'loginSuccess': False
key:value pair. Therefore my guess is that the login requires JavaScript.