You need to enable JavaScript to run this app. 使用Python Requests复现droughtmonitor站点AJAX请求无预期响应
优惠活动
大模型
产品
解决方案
定价
更多

使用Python Requests复现droughtmonitor站点AJAX请求无预期响应

复现网站AJAX请求时返回结果与浏览器观测不匹配

我尝试复现数据表格页的AJAX请求,该站点的AJAX请求由用户在下拉选择框选定选项时触发。

我编写了如下Python请求代码进行测试,但获取到的响应与浏览器开发者工具Network标签页中观测到的对应请求响应不匹配:

import bs4
import requests
import lxml

ses = requests.Session()
ses.get('https://droughtmonitor.unl.edu/Data/DataTables.aspx')
headers_dict = {
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'
}
url = 'https://droughtmonitor.unl.edu/Ajax2018.aspx/ReturnTabularDMAreaPercent_urban'
req_data = {'area':'00064', 'statstype':'1'}
resp = ses.post(url, data=req_data, headers=headers_dict)
    
soup = bs4.BeautifulSoup(resp.content,'lxml')
print(soup)

内容的提问来源于stack exchange,提问作者curious_nustian

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.11 05:36:10