0

I wanted to POST some data to a site using python.

Suppose the data are the following:

payload = {
    'key': 'value',
    'user-point-form-1': random_data #the data I want to post
}

and the html where I want to post that is:

<div class="alert-user-point-a"></div>
<input type="hidden" id="user-point-form-1" value="XXXXXXXXX">

I tried doing response = s.post(url, data=payload) but it seem didnt work. How should I change the request so I post the data where the "XXXXXX" is?

5
  • What is the form target and are you sure it is a POST? Commented Sep 3, 2017 at 20:34
  • And what is s variable? Commented Sep 3, 2017 at 20:35
  • It doesnt have, and yep am sure its a POST, the s is s = requests.Session() a few lines above Commented Sep 3, 2017 at 20:38
  • How do you read random_data and what do you see when you're printing it to stdout ? Commented Sep 3, 2017 at 20:48
  • Suppose random_data="just a text" and am not printing anything in the stdout, just checking if the changes applied to the value on the online site Commented Sep 3, 2017 at 21:06

1 Answer 1

1

So you want to write to a html in a website? This is not techinacally post but I get what you mean... this is more like webscraping. One tool that does that is selenium, but be aware it is quite a mountain to climb. Selenium solves the problem of automating web navigation, using the usual webbrowsers. You have to choose a language (Java, python, etc. etc.) and get a library for the language that links to selenium. Python is pip install selenium. Then you need to install a driver that talks specifically to a browser brand (Firefox, Chrome, Safari). See details of installation here. Next you use the library. It allows you to open windows programatically (silently if you configure that) and send keys to fields, click buttons, etc.

I hope that helps!

Sign up to request clarification or add additional context in comments.

3 Comments

Am confused, isnt that pretty much what I've been doing? I was thinking perhaps the payload "key", or 'user-point-form-1' where wrong
The concept of posting data to html is wrong. You can't do that in a technical sense. What you can do is to build a robot that opens your webbrowser for you and write what you want in the field you want programatically. Is that what you mean by posting data to an html?
Oh I didnt know. I guess if thats the only solution then yes thats what I want, although I would prefer, if it could run it in the background silently without opening chromedriver but thats the result I want, yes.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.