在Python3中打开浏览器页面,每n小时拍摄一次屏幕截图
我想打开一个网页,然后通过python每2小时截图一次。 这是我每隔2小时打开一页的代码在Python3中打开浏览器页面,每n小时拍摄一次屏幕截图,python,python-3.x,module,screenshot,Python,Python 3.x,Module,Screenshot,我想打开一个网页,然后通过python每2小时截图一次。 这是我每隔2小时打开一页的代码 import time import webbrowser total_breaks = 12 break_count = 0 while(break_count < total_breaks): time.sleep(7200) webbrowser.open("https://mail.google.com/mail/u/2") break_count = break_c
import time
import webbrowser
total_breaks = 12
break_count = 0
while(break_count < total_breaks):
time.sleep(7200)
webbrowser.open("https://mail.google.com/mail/u/2")
break_count = break_count + 1
导入时间
导入网络浏览器
总断裂=12
中断计数=0
而(中断次数<总中断次数):
时间。睡眠(7200)
网络浏览器打开(“https://mail.google.com/mail/u/2")
中断计数=中断计数+1
我跟着,但没有取得任何成功
我正在使用python 3.5。我有一个wxpython模块,但它只支持2.x。因此,有没有办法使用python 3每隔2小时拍摄一次屏幕截图呢
pip Install Selenium
安装Seleniumschtask
。
schtask
是windows上的CRON
等价物你试过硒吗?另外,与其执行
time.sleep(7200)
,不如编写一个cronjob,每2小时运行一次。FWIW,可能有比截图更好/更强大的方法来获取您真正想要的信息。如果您有适用于Python 2.x的wxpython,请安装Python 2。x@AnmolSinghJaggi我正在使用windows@ishaan谢谢你的信息。我现在正在看硒。。
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
browser = webdriver.Firefox()
browser.implicitly_wait(30)
browser.get('https://accounts.google.com/ServiceLogin?service=mail&passive=true&rm=false&continue=https://mail.google.com/mail/&ss=1&scc=1<mpl=default<mplcache=2&emr=1&osid=1#identifier')
email = browser.find_element_by_xpath('//*[@id="Email"]')
email.clear()
email.send_keys("email@gmail.com") # change email
email.send_keys(Keys.RETURN)
password = browser.find_element_by_xpath('//*[@id="Passwd"]')
password.clear()
password.send_keys("password") # Change Password
password.send_keys(Keys.RETURN)
time.sleep(10)
browser.save_screenshot('screen_shot.png')
browser.close()
schtasks /Create /SC MINUTE /MO 120 /TN screenshot /TR "PATH_TO_PYTHON_FILE\FILE.py"