gpt4 book ai didi

javascript - 如何在文件名中使用增量编号或不覆盖 18 :00 every day? 的文件来截取网页并保存到硬盘

转载 作者:行者123 更新时间:2023-12-04 02:21:33 24 4
gpt4 key购买 nike

Using HTML5/Canvas/JavaScript to take in-browser screenshots

我遵循上述答案,但没有文件可以保存在本地硬盘上。如何在没有安装外部软件的情况下使用javascript?

Edge on windows
C:\Users\hello\AppData\Local\Packages\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\AC#!001\MicrosoftEdge\User\Default\DOMStore\IS3DHS80

Chrome on windows:
%LocalAppData%\Google\Chrome\User Data\Default\Local Storage\


<html>
<body bgcolor="#000000">
<meta charset="UTF-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>
<script>
function save() {
let region = document.querySelector("body"); // whole screen
html2canvas(region, {
onrendered: function(canvas) {
//let pngUrl = canvas.toDataURL(); // png in dataURL format
//let img = document.querySelector(".screen");
//img.src = pngUrl;
var dat = new Date();
var a = document.createElement("a");
a.href = canvas.toDataURL('image/png');
a.download = dat.toString() + "_MRTG.png";
a.hidden = true;
document.body.appendChild(a);
a.innerHTML = "random";
a.click();
},
});
};

setTimeout(function(){
var today = new Date();
hours = today.getHours();
minutes = today.getMinutes();
if(hours === 18 && minutes === 0){
//save();
let b = document.querySelector("capt");
b.click();
setTimeout(console.log(""),5000);

};
window.location.reload(1);
}, 30000);


</script>
<button onclick="save()" id="capt">Screen Capture</button>
<div id="capture">

<div class="container" id="containerr">
<img width="75%" class="screen">
</div>
</body>
</html>

最佳答案

我知道它不是 javascript,但在 Ubuntu 上,您可以安排以下命令在 cron 作业中运行。

export now=$(date +"%m_%d_%Y") && xdg-open http://www.yahoo.com && sleep 10 && gnome-screenshot > $now.png

它假定要加载的页面将在十秒内加载,并且您的默认浏览器配置了足够低的缩放级别以使整个页面清晰可见。

关于javascript - 如何在文件名中使用增量编号或不覆盖 18 :00 every day? 的文件来截取网页并保存到硬盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58897263/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com