1

我正在尝试抓取 Itunes API 以获取 Apple iTunes 商店中所有可用播客的信息。目前,我一次只能拉200个。当我尝试抓取列表中接下来的 200 个播客时,我得到的 200 个和以前一样。

https://itunes.apple.com/search?term=podcast&limit=2 https://itunes.apple.com/search?term=podcast&limit=2&offset=1

任何建议,将不胜感激。

import requests
import pandas as pd
import time
import json

url = 'https://itunes.apple.com/search?term=podcast&limit=2' 
res = requests.get(url,headers={'User-agent': 'project'})
res.status_code
current_url = None
posts = []
the_offset = 0
for _ in range(2):
    if current_url == None:
        current_url = url

    else:
        current_url = url +'&offset={}'.format(the_offset)
        res = requests.get(current_url)
    if res.status_code != 200:
        print('Error',res.status_code)
        break
    the_offset += 1
    current_dict = res.json()
    current_posts = {k:v for (k,v) in current_dict.items()}
    posts.extend(current_posts['results'])
    print(current_url)
    time.sleep(3)
4

1 回答 1

0

尝试更改偏移参数:

results = 100
limit = 10

pages = int(results / limit)

for i in pages:
    offset = i+1
    request(offset)
于 2019-01-24T02:01:05.183 回答