Created
January 30, 2019 11:23
-
-
Save t9md/0a3e4105189d0391c8169f89c8eb755a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import sys | |
import os | |
from selenium import webdriver | |
from selenium.webdriver.common.action_chains import ActionChains | |
def save_snapshot(driver, word): | |
fname = 'imgs/%s.png' % word | |
if os.path.isfile(fname): | |
print "%s exists!" % fname | |
return | |
driver.get('https://www.google.com/search?tbm=isch&q=' + word) | |
element = driver.find_element_by_id("res") | |
ActionChains(driver).move_to_element(element).perform() | |
driver.save_screenshot(fname) | |
def get_words_from_file(fname): | |
with open(fname) as f: | |
content = f.readlines() | |
content = [x.split("\t")[0] for x in content] | |
return content | |
def retrieve_snapshot_for_words(words): | |
driver = webdriver.Chrome() | |
driver.maximize_window() | |
for word in words: | |
save_snapshot(driver, word) | |
driver.quit() | |
def main(): | |
fname = sys.argv[1] | |
words = get_words_from_file(fname) | |
retrieve_snapshot_for_words(words) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment