【问题标题】:Using google custom search engine to download pics使用谷歌自定义搜索引擎下载图片
【发布时间】:2019-01-06 21:39:59
【问题描述】:

我正在尝试使用谷歌自定义搜索下载一些图片。

我可以返回前 10 张图片的网址。但是当我将范围扩大到 20 张图片时,出现了一些错误。

#initialize service
service = build("customsearch", "v1",
               developerKey=key) 


# search for image
res = service.cse().list(
    q= "apples",
    cx= cx,
    searchType='image',
    num=10,
    fileType='jpg/png',
    safe= 'off'
).execute()
#print the result
if res["items"] is None:
    print("No result")
else:
    for item in res['items']:
        print("Title is:",item['title'], "link is:", item['link'])

代码在 num = 10 时有效,但在 num 超过 10 时失败。 任何人都可以帮助我吗? 我应该怎么做才能让它返回超过 10 个 url?

谢谢!

【问题讨论】:

    标签: google-custom-search google-api-python-client


    【解决方案1】:

    'num' 只能取最大值 10。 为了获得更多结果,您需要使用“开始”参数进行分页。 例如,如果 'num' 为 10,则 start=11 将给出第二页结果。

    https://developers.google.com/custom-search/v1/cse/list

    【讨论】:

      猜你喜欢
      • 2014-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多