def download(self, keyword): site_name = 'badiu' collect = CollectLinks() # initialize chrome driver try: print('==>开始从 {} 搜索图片: {}...'.format(site_name, keyword)) links = collect.baidu(keyword) print('==>开始下载所有图片... {} from {}'.format(keyword, site_name)) self.download_images(keyword, links) print('Done {} : {}'.format(site_name, keyword)) except Exception as e: print('Exception {}:{} - {}'.format(site_name, keyword, e))
def download_from_site(self, keyword, site_code): site_name = Sites.get_text(site_code) add_url = Sites.get_face_url(site_code) if self.face else "" try: collect = CollectLinks( no_gui=self.no_gui) # initialize chrome driver except Exception as e: print('Error occurred while initializing chromedriver - {}'.format( e)) return try: print('Collecting links... {} from {}'.format(keyword, site_name)) if site_code == Sites.GOOGLE: links = collect.google(keyword, add_url) elif site_code == Sites.NAVER: links = collect.naver(keyword, add_url) elif site_code == Sites.BING: links = collect.bing(keyword, add_url) elif site_code == Sites.BAIDU: links = collect.baidu(keyword, add_url) elif site_code == Sites.FLICKR: links = collect.flickr(keyword, add_url) else: print('Invalid Site Code') links = [] print( 'Downloading images from collected links... {} from {}'.format( keyword, site_name)) self.download_images(keyword, links, site_name, max_count=self.limit) print('Done {} : {}'.format(site_name, keyword)) except Exception as e: print('Exception {}:{} - {}'.format(site_name, keyword, e))