0
votes

I need help with this: I need submit/click on 3 different buttons in order on some webpage using request library. So I need click on button1, then button2 and then last one button3. Buttons1,2 dont redirect to another URL, just submit some values, third button is about filling form and submit it then redirect to somewhere else - I need submit this 3 buttons and then get redirect/response url. Url what I am using is some mobile operator web-API-gate, need submit agreements, send phone number and type code what I get.

I dont want use Selenium, I cant use browser, just pure code. Buttons are somewhere in HTML code, but they have specific ID and name, different from each other.

I have something this(showing only 2 buttons):

given_url = something.com/?some_params...

post_data = {'Agree' : 'SubmitAgree'}
submit_agree = requests.post(url=given_url, data=post_data)

post_data = {'Send' : 'SendPhone'}
submit_phone = requests.post(url=given_url, data=post_data)
...


print(submit_phone.content)

What I got from response is None - status code is 200, but None content, dont know why. I was trying use cookies and it is still same. Where is problem, can someone help me ? Is it possible to do this without Selenium ? Thank you

1
Do you know scrapy ? It is used normally to extract (lots of) data but you can just use it to submit forms, if you want to use your code here you have to put more I think so we can get the problem - Saksow

1 Answers

0
votes

From what it looks, requests does not care if you submitted a form before or not it just does every post like a new request.

I suppose the website uses your user session to store previous forms data. So you better use scrapy like I said in my comment, this can help.