John James
John James

Reputation: 657

POST data with python

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?

Upvotes: 0

Views: 111

Answers (1)

Alex
Alex

Reputation: 1262

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!

Upvotes: 1

Related Questions