用puppeteer实现了百度贴吧自动签到小工具
1.安装puppeteer
npm install puppeteer
2.新建app.js,写入如下代码:
const puppeteer = require('puppeteer');
const account = `xxx`;
const password = `xxx`;
const sleep = time =>
new Promise(resolve => {
setTimeout(resolve, time);
});
(async () => {
const browser = await puppeteer.launch({
headless: false,//为了看到运行效果,这里设置false来显示浏览器
args: ['--no-sandbox', '--disable-setuid-sandbox'],
dumpio: false
}); //打开浏览器
const page = await browser.newPage(); //打开一个空白页
await page.goto('https://tieba.baidu.com/index.html', {
waitUntil: 'networkidle2' // 网络空闲说明已加载完毕
}); //打开百度贴吧
await sleep(3000);
await page.click('.u_login a');
await sleep(3000);
await page.click('.tang-pass-footerBarULogin');
await page.type('.pass-text-input-userName', account);
await page.type('.pass-text-input-password', password);
await page.click('.pass-button-submit');
await sleep(3000);
await page.waitForNavigation({
waitUntil: 'load'
}); //等待页面加载出来
await page.click('.onekey_btn');//一键签到按钮
await sleep(3000);
await page.click('.sign_btn_nonmember');//签到
await browser.close(); //关掉浏览器
})();
3.项目根目录下运行 node app.js即可
4.示例效果