Python + selenium + windows定时任务 实现定时每日定时长截图
- 首先下载一个chromdriver插件(插件下载地址:http://chromedriver.storage.googleapis.com/index.html ),之后在小黑窗(win+r)输入cmd,回车,打开黑窗口之后pip install selenium (-i https://pypi.tuna.tsinghua.edu.cn/simple some-package)如果卡就加上清华源
- 普通截图直接使用save_screenshot即可。这里为了实现长截图,需要使用无头浏览(headless)实现。
-
代码如下
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import os
import time
def get_image(url, filename):
#chromedriver的路径
chromedriver = r"D:\python\chromedriver.exe"
os.environ["webdriver.chrome.driver"] = chromedriver
#设置chrome测试开启的模式为headless(无头浏览)
chrome_options = Options()
chrome_options.add_argument('headless')
driver = webd