简体   繁体   English

使用 python 发布请求

[英]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.我试图在 Python 中制作一个用于自动填充网页的脚本,显然给出了正确的输入,然后得到了网页生成的 output,但我是 ZA7F5F35426B9237417ZZI'm 的新手。 The webpage I'm trying to work with is this one: https://t-ict4d.ictp.it/nequick2/nequick-2-web-model我正在尝试使用的网页是这个: https://t-ict4d.ictp.it/nequick2/nequick-2-web-model

I already saw the page source code and opened the "nequick.js"我已经看到页面源代码并打开了“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" }在那里我找到了所需的数据字符串,并且已经在 python 上创建了它,在代码上给出了所有变量值: 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.但是当我执行requests.post(url,data=datastring)时,output 不是我想要从该网页获得的 output。

Does anyone know what's missing for me to get the output like when the webpage is filled directly?有谁知道我在直接填充网页时获得 output 缺少什么?

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如果您遇到问题,请看这里: Python 词典

You will try this way你会尝试这种方式

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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