我正在尝试抓取 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)