class MyOpener(FancyURLopener): #模拟成浏览器
version = 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.10) Gecko/20101005 Fedora/3.6.10-1.fc14 Firefox/3.6.10'
def get_image_url(keyword):#通过关键字搜索找出结果中的图片链接
myopener = MyOpener()
url = "http://www.google.com.hk/search?hl=en&safe=active&biw=1440&bih=675&tbm=isch&sa=1&q='%s'&btnG=Search&oq='%s'&aq=f&aqi=&aql=&gs_sm=s&gs_upl=15301l15500l0l16816l2l2l0l0l0l0l0l0ll0l0" %(keyword,keyword)
page = myopener.open(url)
u = page.read()
href = re.compile(r'imgurl=(?P<imgurl>[^&]+)&')
matches = href.findall(u)
if len(matches) > 0:
while True:
image=random.sample(matches, 1)
if im
version = 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.10) Gecko/20101005 Fedora/3.6.10-1.fc14 Firefox/3.6.10'
def get_image_url(keyword):#通过关键字搜索找出结果中的图片链接
myopener = MyOpener()
url = "http://www.google.com.hk/search?hl=en&safe=active&biw=1440&bih=675&tbm=isch&sa=1&q='%s'&btnG=Search&oq='%s'&aq=f&aqi=&aql=&gs_sm=s&gs_upl=15301l15500l0l16816l2l2l0l0l0l0l0l0ll0l0" %(keyword,keyword)
page = myopener.open(url)
u = page.read()
href = re.compile(r'imgurl=(?P<imgurl>[^&]+)&')
matches = href.findall(u)
if len(matches) > 0:
while True:
image=random.sample(matches, 1)
if im