使用 JavaScript 在一天中的特定时间自动打开浏览器的方法?

发布于 2025-01-11 07:55:37 字数 305 浏览 0 评论 0原文

有没有办法在我的计算机处于打开状态但没有打开任何内容的情况下打开浏览器并使用 JavaScript 自动执行任务?也许使用 NodeJS?澄清一下,我不是在谈论像 window.open() 这样的 JS 方法,而是在硬件级别上自动化任务。

例如:

  1. 周三中午 12:00 打开 Chrome。
  2. 访问 google.com。
  3. 登录。

如果 JavaScript 无法做到这一点,我应该学习哪种语言最接近 JavaScript 语法?

Is there a way to open browser and automate tasks using JavaScript while my computer is on but without having anything opened? Perhaps using NodeJS? Just to clarify, I'm not talking about JS methods like window.open(), I'm talking about automating tasks on hardware level.

For instance:

  1. Open Chrome at 12:00PM on Wednesday.
  2. Go to google.com.
  3. Sign in.

If JavaScript can't do it, what language should I learn that's closest to JavaScript syntax?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

枕梦 2025-01-18 07:55:37

在 Node Js 中,您需要启动一个服务器来为您完成这项工作。这是我用来打开浏览器的代码,其 URL

const { platform } = require('os');
const { exec } = require('child_process');

const WINDOWS_PLATFORM = 'win32';
const MAC_PLATFORM = '达尔文';

const osPlatform = platform();
const args = process.argv.slice(2);
const [url] = args;

if (url === undefined) {
  console.error('Please enter a URL, e.g. "http://www.opencanvas.co.uk"');
  process.exit(0);
}

let command;

if (osPlatform === WINDOWS_PLATFORM) {
  command = `start microsoft-edge:${url}`;
} else if (osPlatform === MAC_PLATFORM) {
  command = `open -a "Google Chrome" ${url}`;
} else {
  command = `google-chrome --no-sandbox ${url}`;
}

console.log(`executing command: ${command}`);

exec(command);

现在您可以花时间使用以下代码,

new Date().getTime()

这些代码的组合有望满足您的需要。谢谢
请阅读本文,了解有关如何登录网站的更多信息 https://marian-caikovski.medium.com/automatically-sign-in-with-google-using-puppeteer-cc2cc656da1c

In Node Js, you need to spin up a server that will do this job for you. Here is the code i have used to open up a browser with a URL

const { platform } = require('os');
const { exec } = require('child_process');

const WINDOWS_PLATFORM = 'win32';
const MAC_PLATFORM = 'darwin';

const osPlatform = platform();
const args = process.argv.slice(2);
const [url] = args;

if (url === undefined) {
  console.error('Please enter a URL, e.g. "http://www.opencanvas.co.uk"');
  process.exit(0);
}

let command;

if (osPlatform === WINDOWS_PLATFORM) {
  command = `start microsoft-edge:${url}`;
} else if (osPlatform === MAC_PLATFORM) {
  command = `open -a "Google Chrome" ${url}`;
} else {
  command = `google-chrome --no-sandbox ${url}`;
}

console.log(`executing command: ${command}`);

exec(command);

Now you can get time with following code

new Date().getTime()

Combination of these will be hopefully work the thing you need. thanks
Please follow this article for further information on how to sign into a website https://marian-caikovski.medium.com/automatically-sign-in-with-google-using-puppeteer-cc2cc656da1c

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文