Created
June 15, 2017 01:01
-
-
Save imfht/04adc40d927e0fab72ef5d6a8aa1340e to your computer and use it in GitHub Desktop.
a page shoot program.
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
def shoot(url): | |
""" | |
shoot and return picture path | |
""" | |
try: | |
driver = webdriver.PhantomJS( | |
executable_path='/home/ubuntu/phantomjs-2.1.1-linux-x86_64/bin/phantomjs') # or add to your PATH | |
except Exception as e: | |
print 'Exception found' | |
print e | |
return | |
driver.set_window_size(1024, 768) # optional | |
while not que.empty(): | |
item = que.get() | |
url = item['number'] | |
finger = item['title'] | |
floder_name = urlparse(url)[1] | |
filename = '%s_%s' % (hashlib.md5(url).hexdigest(), get_timestamp()) | |
driver.get(url) | |
if not (os.path.exists(floder_name)): | |
try: | |
os.mkdir('%s/%s' % (BASE_PATH, floder_name)) | |
except OSError as exc: # Python >2.5 目录已经存在 | |
''' | |
from https://stackoverflow.com/questions/600268/mkdir-p-functionality-in-python/600612#600612 | |
''' | |
if exc.errno == errno.EEXIST and os.path.isdir('%s/%s' % (BASE_PATH, floder_name)): # @todo 写得太绕了 | |
pass | |
else: | |
raise | |
if not driver.save_screenshot('/%s/%s.png' % (floder_name, filename)): # save a screenshot to disk | |
print 'fuck_ , I got a error' | |
return False | |
else: | |
return '/%s/%s.png' % (floder_name, filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment