0

I would like to automatically fill a form in my website using another website. I would like to get the content after this form below were processed. I read some topics (1, 2, 3) related to it, but I'm a bit confused which fields are necessary to send and how to send them. This is the form from my fictitious url:http://fix-tt.mary.com/tmtrack/tmtrack.dll

<form name="Login" id="Login" method="POST">
  <input name="TMBNX" type="hidden" value="ISO-8859-1">
  <input name="postpreservationdata" type="hidden" value="">
  <input name="target" type="hidden" value="HTTP%3A%2F%2Ffix-tt.mary.com%2Ftmtrack%2Ftmtrack.dll%3FPage%26Id%3D4245024%26template%3Dviewwrapper%26TableId%3D1003">
  <input name="smauthreason" type="hidden" value="0">
  <input name="smtryno" type="hidden" value=""> 
  <input name="smretries" type="hidden" value="1">
  <input name="bacmonitoring" type="hidden" value="LOG ON">

  <h3>Use your email address</h3>

  <label>Email address:</label>
  <input name="USER" type="text">
  <div class="email-login-help clearfix">
    <span class="help">Format: user@test.com</span>
  </div>
  <br>

    <label>Computer password:</label>
    <input name="PASSWORD" class="computer-pass text" onpaste="return false" type="password" autocomplete="off">

    <div class="submit-row"><input class="btn btn-primary" onclick="javascript:trimAndSubmit();" type="submit" value="Log on"> </div>

    <br>
</form>

Any idea how to do it ?

Community
  • 1
  • 1
Valter Silva
  • 15,646
  • 48
  • 123
  • 210
  • Use wget http://stackoverflow.com/questions/1324421/how-to-get-past-the-login-page-with-wget – stark Oct 15 '14 at 14:39

1 Answers1

1

If you want to do this in Python then you could use the Requests library:

http://docs.python-requests.org/en/latest/user/quickstart/#more-complicated-post-requests

import requests
payload = {'USER': 'user@email.com',
           'PASSWORD': 'password123',
           'TMBNX': 'ISO-8859-1',
           'smauthreason': 0,
           'smretries': 1,
           'bacmonitoring': 'LOG ON',
           'target': 'http://fix-tt.mary.com/tmtrack/tmtrack.dll',

           }
r = requests.post("http://path-to-login-page.com", data=payload)
print(r.text)

The above code is just a guess at which fields might be required, it could be that only username and password are required. The guess was based on which fields had default parameters specified. This should be a good start though.

Valter Silva
  • 15,646
  • 48
  • 123
  • 210
Hairy Chris
  • 1,407
  • 14
  • 23
  • It works perfectly! Thank you! I had to use a [proxy][1] to access the web site properly, but your help was essential! Thanks! [1]: http://stackoverflow.com/questions/8287628/proxies-with-python-requests-module – Valter Silva Oct 16 '14 at 11:31