keyword = '美女'.decode('utf8') # 要搜索的关键字 addtional = {'width':'1920', 'height':'1200'} # 宽度和高度 可以为空 {} directory = r'image' # 存放的位置 count = 500 # 要下载的数量,自动进到20的倍数 # 代理设置 proxy = 'http://localhost:7001' use_proxy = False # 开始准备 if use_proxy: # 设置代理 proxy_install(proxy) while_n = 0 # 循环计数器 imglist = [] makedir(directory) print 'Generate search url' searchURL = search(keyword.encode('gbk'), addtional) # 下载 ############# # 获取搜索结果数量并与count比较取其较小值 count = min(searchResult(searchURL), count) # 没有搜索结果时退出 if not count: print "No search result at current condition." sys.exit(1) # 获得指定数量的url, 存放于list ,one page by one page print 'Fetching page', while len(imglist) < count: print while_n, #mark the times of while while_n += 1 tmplist = getImageUrlList(searchURL) imglist = imglist + tmplist
def baseURL(): if Config.site == 'baidu': return search(Config.keyword, Config.addtional) if Config.site == 'jandan': return 'http://jandan.net/ooxx'
def base_url(keyword): """set base url from config""" if Config.SITE == 'baidu': return search(keyword, Config.ADDTIONAL) if Config.SITE == 'jandan': return 'http://jandan.net/ooxx'