我想获取Google apiclient.discovery查询产生的图片网址。使用下面的代码我可以获得前10个图像,但是当我在查询中添加字段'start'以迭代接下来的10个图像时,我收到以下错误消息:
HttpError:https://www.googleapis.com .....“无效的价值”>
我的代码:
from apiclient.discovery import build
curr_idx = 0
service = build("customsearch", "v1",developerKey="***mykey***")
for query in range(3):
res = service.cse().list(
q='cat',
cx='***myengine***',
searchType='image',
start=curr_idx,
num=10,
).execute()
for item in res['items']:
print item['title']
curr_idx = curr_idx + 1
有谁知道为什么?
答案 0 :(得分:0)
我找到了解决方案。 curr_idx必须是一个字符串,初始值应该是1而不是0.所以这是最终的代码
from apiclient.discovery import build
curr_idx = 1
service = build("customsearch", "v1",developerKey="***mykey***")
for query in range(3):
res = service.cse().list(
q='cat',
cx='***myengine***',
searchType='image',
start=str(curr_idx),
num=10,
).execute()
for item in res['items']:
print item['title']
curr_idx = curr_idx + 1