我请求Meetup API提供590页。我使用while循环进行迭代以获取页面。现在我有了页面,我需要请求这些页面,并将它们正确地格式化为python,以便放置到一个数据帧中。你知道吗
This is how it looks when you do it for one url :
url = ('https://api.meetup.com/2/groups?offset=1&format=json&category_id=34&photo-host=public&page=100&radius=200.0&fields=&order=id&desc=false&sig_id=243750775&sig=768bcf78d9c73937fcf2f5d41fe6070424f8d0e3')
r = requests.get(url).json()
data = pd.io.json.json_normalize(r['results'])
But because I have so many pages I want to do this automatically and iterate through them all.
这就是嵌套while循环出现在脑海中的方式,这就是我尝试的:
urls = 0
offset = 0
url = 'https://api.meetup.com/2/groups?offset=%d&format=json&category_id=34&photo-host=public&page=100&radius=200.0&fields=&order=id&desc=false&sig_id=243750775&sig=768bcf78d9c73937fcf2f5d41fe6070424f8d0e3'
r = requests.get(urls%d = 'https://api.meetup.com/2/groups?offset=%d&format=json&category_id=34&photo-host=public&page=100&radius=200.0&fields=&order=id&desc=false&sig_id=243750775&sig=768bcf78d9c73937fcf2f5d41fe6070424f8d0e3').json()
while urlx < 591:
new_url = r % urls % offset
print(new_url)
offset += 1
但是,它不起作用,我收到许多错误,包括以下错误:
SyntaxError: keyword can't be an expression
不知道你想做什么,代码有很多问题。你知道吗
但是,如果您只想在0到591之间循环并获取URL,那么下面是代码:
相关问题 更多 >
编程相关推荐