Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在单次命中Python请求中从API获取所有数据_Python_Api_Python 2.7_Get_Python Requests - Fatal编程技术网

在单次命中Python请求中从API获取所有数据

在单次命中Python请求中从API获取所有数据,python,api,python-2.7,get,python-requests,Python,Api,Python 2.7,Get,Python Requests,虽然第一次在浏览器中点击基本url,但最后3个参数未显示在requests查询参数中,但其工作正常 当我点击这个API时,它返回一个包含2个键的json(总计和结果)。 结果键包含字典列表(这是主要数据)。另一个键是“total”,它包含Justdial中可用的不同类别的总数 在本例中,它是total=49,因此必须命中api 3次,因为api一次只返回24个结果(24+24+1,所以我们需要命中3次) 我的问题是,有没有办法一次获得完整的json?我的意思是,有49个结果,因此,我们可以在一次

虽然第一次在浏览器中点击基本url,但最后3个参数未显示在requests查询参数中,但其工作正常

当我点击这个API时,它返回一个包含2个键的json(总计和结果)。 结果键包含字典列表(这是主要数据)。另一个键是“total”,它包含Justdial中可用的不同类别的总数

在本例中,它是total=49,因此必须命中api 3次,因为api一次只返回24个结果(24+24+1,所以我们需要命中3次)


我的问题是,有没有办法一次获得完整的json?我的意思是,有49个结果,因此,我们可以在一次命中中获得所有数据(所有49个类别),而不是将api命中3次。我已经在params中尝试了很多组合,但没有成功。

通常API有一个
count
max_results
参数——在URL上设置此参数,您将获得更多结果


以下是Twitter API
count
参数的文档:

Github API要求您检索页面中的数据(每页最多100个结果),响应dict有一个“链接”条目,其中包含指向下一页结果的url

下面的代码迭代组织中的所有团队,直到找到它正在寻找的团队

import requests
url = 'http://www.justdial.com/autosuggest.php?'
param = {
        'cases':'popular',
        'strtlmt':'24',
        'city':'Mumbai',
        'table':'b2c',
        'where':'',
        'scity':'Mumbai',
        'casename':'tmp,tmp1,24-24',
        'id':'2'
}
res = requests.get(url,params=param)
res = res.json()

真正地它既不工作
计数
也不工作
最大结果
。我将这个url与count和max_结果一个接一个地结合使用,并在chrome plugin
postman
中进行了尝试,但相同的结果(我的意思是24)检查JustDial.com API文档,它可能被命名为其他名称,或者不存在
    params = {'page': 1, 'per_page':100}
    another_page = True
    api = GH_API_URL+'orgs/'+org['login']+'/teams'
    while another_page: #the list of teams is paginated
        r = requests.get(api, params=params, auth=(username, password))
        json_response = json.loads(r.text)
        for i in json_response:
            if i['name'] == team_name:
                return i['id']
        if 'next' in r.links: #check if there is another page of organisations
            api = r.links['next']['url']