我正在尝试抓取iTunes API以获取Apple iTunes商店中所有播客的信息。目前,我一次只能拉 200 个。当我尝试抓取列表中的下一个 200 个播客时,我得到的 200 个和以前一样
。https://itunes.apple.com/search?term=podcast&limit=2https://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)
尝试更改偏移量参数:
results = 100
limit = 10
pages = int(results / limit)
for i in pages:
offset = i+1
request(offset)