使用请求库使用python模拟ajax请求 [英] Simulating ajax request with python using the requests lib

查看:137
本文介绍了使用请求库使用python模拟ajax请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我致电 https://www.shirtinator.de/cT=search时/motives& sq = junggesellenabschied 在上方,您可以切换到另一侧,并在显示的50到100个动机之间进行切换.

when i call https://www.shirtinator.de/cT=search/motives&sq=junggesellenabschied at the upper you get the possiblity to switch to next side and to switch between 50 and 100 motives displayed.

我尝试使用pythons请求进行编码,后请求包含ajax脚本的参数,分别在50和100之间更改以在侧面更改.

I try to code ,using pythons requests, the post request including the parameter for the ajax script to change between 50 and 100 respectively to change betwenn the side.

我使用了chromes开发人员工具来检测邮寄请求的邮寄表格数据.

I used chromes developer tools to detect the post formsform data of the post request.

这是我的脚本,无法提供所需的数据.

This is my script, whicht do not deliver the desired data.

import requests
import json

url = "https://www.shirtinator.de/?cT=search/motives&sq=junggesellenabschied"
data1= {"xajax":"searchBrowse","xajaxr":"1455134430801","xajaxargs[]":"1","xajaxargs[]":"true","xajaxargs[]":"true","xajaxargs[]":"motives","xajaxargs[]":"100"}
r = requests.post(url, data=data1)
result = r.text
print result

感谢支持.

最佳

推荐答案

在创建dict(data1)时多次使用同一键时,最后一个值将覆盖所有先前出现的值. 就您而言,您得到的是:

When you use the same key more than once when creating the dict (data1), the last value will override all previous occurrences. In your case, what you get is:

In [2]: data1= {"xajax":"searchBrowse","xajaxr":"1455134430801","xajaxargs[]":"1","xajaxargs[]":"true","xajaxargs[]":"true","xajaxargs[]":"motives","xajaxargs[]":"100"}

In [3]: data1
Out[3]: {'xajax': 'searchBrowse', 'xajaxargs[]': '100', 'xajaxr': '1455134430801'}

如您所见,xajaxargs []参数并未包含应作为数组包含的所有值.以请求可以理解的方式执行此操作的正确方法是使xajaxargs []的值成为这些值的列表:

As you can see, the xajaxargs[] parameter does not contain all the values it should contain as an array. The correct way to do this in a way that requests will understand is to make the value of xajaxargs[] a list of these values:

In [4]: data1= {"xajax":"searchBrowse","xajaxr":"1455134430801","xajaxargs[]":["1", "true", "true", "motives","100"]}

这篇关于使用请求库使用python模拟ajax请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆