简体   繁体   中英

Post Request using python

I was trying to make a script in Python for the automatic filling of a webpage, obviously giving the ight inputs and then getting the output generated by the webpage, but I'm new with Python so I'm a little lost. The webpage I'm trying to work with is this one: https://t-ict4d.ictp.it/nequick2/nequick-2-web-model

I already saw the page source code and opened the "nequick.js"

There I found the datastring needed and already made it on python, giving all variables values previously on the code: datastring = { "lat1":"lat1", "lon1":"lon1", "h1":"h1", "lat2":"lat2", "lon2":"lon2", "h2":"h2", "year":"year", "month":"month", "day":"day", "hour":"hour", "localtime":"localtime", "user":"user", "r12_f":"r12_f", "sol_val":"sol_val", "itu":"itu" }

but then when I do requests.post(url,data=datastring) , the output is not the output that I want from that webpage.

Does anyone know what's missing for me to get the output like when the webpage is filled directly?

Thank you!

The way you're creating your dictionary is wrong, should be:

"lat1":lat1,"lon1":lon1,"h1":h1,...

Have a look here if you're having some trouble: Python dictionaries

You will try this way

r = request.post(url,data=datastring)
print(r.json()) or print(r.text)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM