Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Python3中打开浏览器页面,每n小时拍摄一次屏幕截图_Python_Python 3.x_Module_Screenshot - Fatal编程技术网

在Python3中打开浏览器页面,每n小时拍摄一次屏幕截图

在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

我想打开一个网页,然后通过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_count + 1
导入时间
导入网络浏览器
总断裂=12
中断计数=0
而(中断次数<总中断次数):
时间。睡眠(7200)
网络浏览器打开(“https://mail.google.com/mail/u/2")
中断计数=中断计数+1
我跟着,但没有取得任何成功
我正在使用python 3.5。我有一个wxpython模块,但它只支持2.x。因此,有没有办法使用python 3每隔2小时拍摄一次屏幕截图呢

  • 在命令提示符下使用pip
    pip Install Selenium
    安装Selenium

  • 确保环境变量中有python路径

  • 通过更改下面的电子邮件和密码来运行此脚本

  • 最后,您可以从命令提示符对保存的python文件运行
    schtask
    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&ltmpl=default&ltmplcache=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"