trying to delay part of my program

感情迁移 提交于 2021-02-05 11:42:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!