0

I have been trying to submit form request but can't. I tried to send using Request library. I am not able to figure out the parameters to be sent. There is just a textarea and submit button. Here is the website source:

<form class="form-horizontal">
<input id="RId" type="hidden" value="Some_XYZ_Code" />
  <div class="row">
  <div class="col-md-12">
  <div id="TextContainer" class="textarea-container">
  <textarea id="Text" rows="5" maxlength="700" class="abc"></textarea>
  </div>
  </div>
  <div class="col-md-12">
  <button id="Send" class="btn btn-primary-outline" type="button"   onclick="SendMsg()" data-loading-text="Loading..."><span class="icon icon-pencil"></span> Send</button>
  </div>
  </div>
  </form>

My Code goes like:

import requests
r = requests.post("https://akshitdhar.sarahah.com/",
              data={'id':'RId','value':'Some_XYZ_Code','Text':'abc'})
print(r.status_code)
2
  • That can't be the website source, as none of the fields have name attributes. Are you sure the form is being submitted directly? Commented Sep 28, 2017 at 15:30
  • If you look carefully it is not submitting the form, it is calling JS function SendMsg() instead. Commented Sep 28, 2017 at 15:38

1 Answer 1

1

Posting message to Sarahah:

def makePost2User(userId, msg):
    r = requests.get("https://%s.sarahah.com/" % userId);

    if (r.status_code != 200):
        print("Error making GET Request. Server returned Code: %s" % r.status_code)
        pass

    cookie = r.headers['Set-Cookie'].split(";")[0]
    print("Cookie: %s" % cookie)
    headers = { 'Cookie': cookie }

    tstr = r.content.decode().split("<input id=\"RecipientId\" type=\"hidden\" value=\"")[1]
    uId = tstr.split("\"")[0]
    print("UserID: %s" % uId)

    tstr = r.content.decode().split("name=\"__RequestVerificationToken\" type=\"hidden\" value=\"")[1]
    rToken = tstr.split("\"")[0]
    print("Token: %s" % rToken)

    url = "https://%s.sarahah.com/Messages/SendMessage" % userId
    data = { "__RequestVerificationToken":rToken, "userId": uId, "text": msg }

    p = requests.post(url, headers=headers, data=data)
    print("Posted. Server returned Code: %s" % p.status_code)
    pass
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.