Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用google customsearch api下载图像_Python_Api_Google Custom Search - Fatal编程技术网

Python 使用google customsearch api下载图像

Python 使用google customsearch api下载图像,python,api,google-custom-search,Python,Api,Google Custom Search,我的问题可能很琐碎。但是我尝试配置我的customsearch引擎来下载google image的前10个结果。下面是python脚本。它的工作,除了比我的结果一个非常远的谷歌图像与相同的参数之一。有人能告诉我我错过了什么吗 # -*- coding: utf-8 -*- import os import sys from urllib import FancyURLopener import urllib2 import simplejson from apiclient.discovery

我的问题可能很琐碎。但是我尝试配置我的customsearch引擎来下载google image的前10个结果。下面是python脚本。它的工作,除了比我的结果一个非常远的谷歌图像与相同的参数之一。有人能告诉我我错过了什么吗

# -*- coding: utf-8 -*-
import os
import sys
from urllib import FancyURLopener
import urllib2
import simplejson
from apiclient.discovery import build


class MyOpener(FancyURLopener): 
    version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'
myopener = MyOpener()

service = build("customsearch", "v1",
               developerKey="** my Key **")

res = service.cse().list(
    q='SearchTerm',
    cx='** my cx**',
    searchType='image',
    num=10,
    imgType='photo',
    fileType='jpg',
    imgSize="xxlarge"
).execute()

count=0
for item in res['items']:
  myopener.retrieve(item['link'],str(count))
  count=count+1

我可能完全错了,但谷歌在返回结果时做了大量定制。根据所使用的浏览器或操作系统的类型,甚至考虑的位置,您可能会看到不同的结果。我建议您打开两个不同的浏览器,看看是否得到相同类型的结果。这是一个关于这个的TED演讲,谢谢。但在这里,我的意思是非常不同的:例如,当我要一瓶葡萄酒时,我得到了风景葡萄园