【问题标题】:Post Request using python使用python发布请求
【发布时间】:2021-05-01 00:02:32
【问题描述】:

我试图用 Python 编写一个用于自动填充网页的脚本,显然是给出正确的输入,然后得到网页生成的输出,但我是 Python 新手,所以我有点迷茫。 我正在尝试使用的网页是这个: https://t-ict4d.ictp.it/nequick2/nequick-2-web-model

我已经看到页面源代码并打开了“nequick.js”

在那里,我找到了所需的数据字符串,并且已经在 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" }

但是当我执行requests.post(url,data=datastring) 时,输出不是我想要的那个网页的输出。

有谁知道我在直接填充网页时获得输出时缺少什么?

谢谢!

【问题讨论】:

    标签: python python-requests http-post python-requests-html


    【解决方案1】:

    您创建字典的方式是错误的,应该是:

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

    如果您遇到问题,请看这里:Python dictionaries

    【讨论】:

    • 好的,谢谢!那是一个错误,但输出仍然不正确
    【解决方案2】:

    你会这样尝试

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-06-01
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多