问题
Im trying to take a snapshot of the webpage i open but i need to delay the second part of the code so that the program has time to open the page
Here is the code
import os
import sys
import time
import Image
import ImageGrab
import webbrowser
webbrowser.open_new(input("URL: "))
#Need to delay here
SaveDirectory=r'C:\Documents and Settings\User\My Documents\My Pictures'
ImageEditorPath=r'C:\WINDOWS\system32\mspaint.exe'
img=ImageGrab.grab()
box = (100, 100, 400, 400)
region = img.crop(box)
saveas=os.path.join(SaveDirectory,'ScreenShot_'+'.png')
img.save(saveas)
editorstring='""%s" "%s"'% (ImageEditorPath,saveas)
os.system(editorstring)
回答1:
you can try to use time.sleep(seconds) to let your program delay for a while.
回答2:
taking a screenshot with selenium webdriver bindings for python:
#!/usr/bin/env python
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://www.google.com/')
browser.save_screenshot('screenshot.png')
browser.quit()
来源:https://stackoverflow.com/questions/16026872/trying-to-delay-part-of-my-program