Python 中的往返分页

问题描述 投票:0回答:1

全部,

这可能是一个相当新手的问题,但我不知道如何在 Python 中做到这一点。我需要做的是,在从 Panaramio 请求数据时设置 to 和 from 参数。

http://www.panoramio.com/map/get_panoramas.php?set=public&from=0&to=100&minx=-180&miny=-90&maxx=180&maxy=90&size=medium&mapfilter=true

Panoramio 只允许您一次返回 100 条记录,因此我需要构建 url 字符串来显示 100 组记录的进度。例如。 101-200、201-300 等。是否有任何示例可以向我展示如何使用 Python 进行此类分页?

谢谢, 亚当

更新: 下面的例子似乎做了我想做的事情。现在我必须弄清楚如何从 101-200、201-300 等进行实际迭代...从那里我可以获取这些值并构建我的查询字符串。这有道理吗?

def counter(low, high):
    current = low
    while current <= high:
        yield current
        current += 100

if __name__ == '__main__':

    for c in counter(100, 200):
        print c

更新#2:我让它变得比应有的更难

def counter(low, high):
    while low <= high:
        yield low, high
        low += 100   
        high += 100  

for i in counter(1, 100):
        print i
python pagination iteration panoramio
1个回答
0
投票
for number in range(1, 301, 100):
    low = number
    high = low + 100
© www.soinside.com 2019 - 2024. All rights reserved.