我正在准备一个python 3.7程序,它将获取我保存在给定文件夹中的所有html文件,打开它们并截取每个文件的屏幕快照。问题是我不能拍全屏的截图。
我有python代码,可以在chrome中打开每个html文件并截图,但是我希望截图是全屏的,这样以后就不必裁剪图像文件了。我有打开chrome全屏的代码,但这似乎不允许我在同一个全屏打开html文件。
import glob
import os
import pyautogui
import webbrowser
import time
import sys
import subprocess
from PIL import Image
#Set folder containing HTML files.
glob_folder = os.path.join(path_folder, '*.html')
# All HTML in folder
html_file_list = glob.glob(glob_folder)
for html_file in html_file_list:
temp_name = "file://" + html_file
# Opening HTML file in Chrome - this does not open as fullscreen
webbrowser.open(temp_name,new=0,autoraise=True)
time.sleep(2)
newstr = html_file.replace(".html","")
screen= newstr + r'.png'
# Taking screenshot and cropping - I would like to avoid this by taking the
screenshots in fullscreen
pyautogui.screenshot(screen)
img = Image.open(screen)
box = (1, 100, 1850, 1035)
area = img.crop(box)
png = screen.rsplit('\\', 1)[-1]
area.save(png)
我尝试了下面的代码以全屏方式打开chrome,但是当我将它与上面的代码结合时,它无法正常工作。
import os
import subprocess
CHROME = os.path.join("C:\Program
Files(x86)\Google\Chrome\Application\chrome.exe")
os.system('taskkill /im chrome.exe')
subprocess.call([CHROME, '--kiosk'])
os.system('taskkill /im chrome.exe')
这给了我给定文件夹中每个html文件的截图,但是需要使用裁剪,我希望通过全屏截图来避免。非常感谢!