自动签到之实现掘金模拟签到
一,环境准备
node 下载安装
node版本:22.14.0

安装好后,进行npm国内源设置
npm国内源设置
打开cmd,复制粘贴下面命令,回车即可
npm config set registry https://registry.npmmirror.com/
验证命令:npm get registry

npm、yarn、pnpm 设置最新国内镜像源(附官方镜像源和最新阿里源),以及 nrm 的使用教程【2025】 | kshao-blog-前端知识记录 (ksh7.com)
二,具体流程
1.首先是代码
const schedule = require('node-schedule');
const puppeteer = require('puppeteer');let browserInstance;
(async () => {browserInstance = await puppeteer.launch({headless: false,defaultViewport: {width: 0,height: 0}});
})()
// 每晚9点开始签到
const resetOnlineTimeJob = schedule.scheduleJob('0 9 * * *', async () => { // 注意时间格式是24小时制const b = Math.floor(Math.random() * 60000)console.log('在' + b + '毫秒后开始签到');setTimeout(aa, b)
});
async function aa() {const page = await browserInstance.newPage();// 设置导航超时时间为60秒(单位为毫秒)await page.setDefaultNavigationTimeout(60000);try {// 导航到指定的页面await page.goto('https://juejin.cn/user/center/signin?from=main_page');// 等待5秒await delay(5000);// 检查并点击签到按钮if (await page.$('.signin.btn')) {await page.click('.signin.btn');console.log('找到.signin.btn');}else if (await page.$('.signedin.btn')) {await page.click('.signedin.btn');console.log('找到.signedin.btn');}// 等待5秒await delay(5000);// 等待并点击 btn-area 中的 btn 按钮// await page.waitForSelector('.btn-area .btn');// if (await page.$('.btn-area .btn')) {// console.log('找到.btn-area .btn');// await page.click('.btn-area .btn');// }// 确保该元素可以点击await page.waitForSelector('.btn-area .btn', { visible: true });await page.waitForFunction(selector => {const element = document.querySelector(selector);return element && !element.disabled && element.offsetWidth > 0 && element.offsetHeight > 0;},{ timeout: 5000 },'.btn-area .btn');await page.click('.btn-area .btn');console.log('签到成功');// 等待3秒await delay(3000);// 等待并点击抽奖按钮await page.waitForSelector('#turntable-item-0');if (await page.$('#turntable-item-0')) {await page.click('#turntable-item-0');}console.log('抽奖成功');// 等待3秒然后关闭页面await delay(3000);// await page.close();} catch (error) {console.log(error);// await page.close();}
}
function delay(time) {return new Promise(function (resolve) {setTimeout(resolve, time)});
}console.log('<strong><font color="#FF0000">掘金</font></strong>自动签到已启动');
代码转自:
掘金自动签到 - 吾爱破解 - 52pojie.cn
https://www.52pojie.cn/forum.php?mod=viewthread&tid=2000354&highlight=%BE%F2%BD%F0
2项目初始化
随便打开一个文件夹,自己能找到的,复制上面代码,然后新建txt文件,粘贴进去,随后改名为server.js
(其实命名也是可以自己修改,看你心情)

运行npm init,初始化项目

一路回车即可
或者不需要初始化项目
直接安装依赖
npm i node-schedule

npm i puppeteer

3.运行命令及使用
运行 node server.js

登录到掘金,然后自动执行签到l
三,注意事项
不能关闭窗口,结束
