我可以用python中的web抓取请求作为带有POST方法的请求URL吗

2024-09-26 17:46:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用python中的请求来访问网页刮取此页面:

在网页https://www.otpbanka.hr/tecajna-lista上有请求URL:https://www.otpbanka.hr/otp/ajax/exchange,但方法是POST

enter image description here

在dev tools In Response选项卡中,我可以看到内容的JSON代码,但有没有一种方法可以在Python中读取它

enter image description here

多谢各位


Tags: 方法httpsdevurl网页exchangewwwhr
1条回答
网友
1楼 · 发布于 2024-09-26 17:46:43

快速查看一下请求,似乎有一个表单数据也要传递,以便服务器响应所需的结果,否则它只会返回什么(无主体)

尝试:

import requests

query_data = {
    "q1": "latest",
    "q2": "OTP",
    "q3": '',
    "q4": 'DISPLAY'
}

response = requests.post('https://www.otpbanka.hr/otp/ajax/exchange', data = query_data)

if response.status_code == 200:
    print(response.json())
else:
    print(response.status_code)

相关问题 更多 >

    热门问题