我正在尝试从itunesapi中获取苹果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)
尝试更改偏移参数:
相关问题 更多 >
编程相关推荐