// An highlighted block
const puppeteer = require('puppeteer');
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
(async() => {
//const browser = await puppeteer.launch();
const browser = await puppeteer.launch({
headless: true //设置成false 会触发浏览器打开,完整的看到机器人工作的过程。
});
global.page = await browser.newPage();
global.page.setDefaultNavigationTimeout(9980000);
await global.page.goto('https://ads.tiktok.com/i18n/signup/');
await global.page.setViewport({
width: 1280,
height: 2200
});
await sleep(1000);
await global.page.screenshot({ path: './us/home.png', fullpage: true });
// await browser.close();
console.log("注册");
const nextSelect = await global.page.$(".vi-input--suffix");
await nextSelect.click();
await global.page.waitFor(2000);
// await selects[1].click()
await global.page.screenshot({ path: './us/nextSelect1.png' });
await global.page.waitFor('ul.vi-scrollbar__view > li:nth-child(232)'); //等待选项出现
await global.page.waitFor(2000);
await global.page.click('ul.vi-scrollbar__view > li:nth-child(232)'); //点击选项桃子
await global.page.waitFor(2000);
await global.page.screenshot({ path: './us/nextSelect2.png' });
const nextBtn = await global.page.$(".next-btn");
await nextBtn.click();
await global.page.screenshot({ path: './us/next-btn.png' });
console.log("跳转");
const dangerBtn = await global.page.$(".vi-button--danger");
// const newPagePromise = new Promise(x => browser.once('targetcreated', target => x(target.page()))); // 声明变量
await dangerBtn.click();
//const newPage = await newPagePromise; // newPage就是a链接打开窗口的Page对象
await global.page.waitFor(2000);
global.page.waitForNavigation({ waitUntil: "networkidle0" })
await global.page.screenshot({ path: './us/vi-button--danger.png' });
await global.page.waitFor(2000);
console.log("email");
const mailInput = await global.page.$$("input[name=email]");
await mailInput[1].focus();
await global.page.screenshot({ path: './us/mailInput1.png' });
await global.page.keyboard.type('405659098@qq.com');
await global.page.screenshot({ path: './us/mailInput2.png' });
console.log("password");
const passwordInput = await global.page.$("input[name=password]");
await passwordInput.focus();
await global.page.screenshot({ path: './us/passwordInput1.png' });
await global.page.keyboard.type('Wv19930227!');
await global.page.screenshot({ path: './us/passwordInput2.png' });
console.log("password");
const rePasswordInput = await global.page.$("input[name=repeatPwd]");
await rePasswordInput.focus();
await global.page.keyboard.type('Wv19930227!');
await global.page.screenshot({ path: './us/rePasswordInput.png' });
const regBtn = await global.page.$("#TikTokAds_Register-account-center-code-btn");
await regBtn.click();
await global.page.screenshot({ path: './us/regBtn.png' });
const checkBtn = await global.page.$(".account-center-agreement-check");
await checkBtn.click();
await global.page.screenshot({ path: './us/checkBtn.png' });
let reg = async function(code) {
console.log("code", code);
const codeInput = await global.page.$("input[name=code]");
await codeInput.focus();
await global.page.keyboard.type(code);
await global.page.screenshot({ path: './us/codeInput.png' });
const accountBtn = await global.page.$(".account-center-action-button");
await accountBtn.click();
await global.page.screenshot({ path: './us/accountBtn.png' });
await global.page.waitFor(2000);
await global.page.screenshot({ path: './us/end.png' });
await browser.close();
}
var Imap = require('imap')
var MailParser = require("mailparser").MailParser
var fs = require("fs")
// 引入cheerio模块
const cheerio = require('cheerio')
global.code = ''
global.user = '405659098@qq.com'
var imap = new Imap({
user: global.user, //你的邮箱账号
password: 'shjiketfxrsocabh', //你的邮箱密码
host: 'imap.qq.com', //邮箱服务器的主机地址
port: 993, //邮箱服务器的端口地址
tls: true, //使用安全传输协议
// connTimeout: 60000,
tlsOptions: { rejectUnauthorized: false } //禁用对证书有效性的检查
});
function openInbox(cb) {
imap.openBox('INBOX', true, cb);
}
imap.once('ready', function() {
openInbox(function(err, box) {
console.log("打开邮箱")
if (err) throw err;
imap.search(['UNSEEN', ['SINCE', 'May 20, 2018']], function(err, results) { //搜寻2017-05-20以后未读的邮件
if (err) throw err;
var f = imap.fetch(results, { bodies: '' }); //抓取邮件(默认情况下邮件服务器的邮件是未读状态)
f.on('message', function(msg, seqno) {
var mailparser = new MailParser();
msg.on('body', function(stream, info) {
stream.pipe(mailparser); //将为解析的数据流pipe到mailparser
//邮件头内容
// mailparser.on("headers", function(headers) {
// if (headers.get('subject') === 'TikTok for Business Verification Code') {
// console.log("邮件头信息>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
// console.log("邮件主题: " + headers.get('subject'));
// console.log("发件人: " + headers.get('from').text);
// // console.log("收件人: " + headers.get('to').text);
// }
// });
// console.log(mailparserSubject)
// 邮件内容
mailparser.on("data", function(data) {
if (data.type === 'text') { //邮件正文
console.log("邮件内容信息>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
//console.log("邮件内容: " + data.html);
// 加载HTML字符串
const $ = cheerio.load(data.html)
if ($('title') && $('title').text() && $('title').text() === 'TikTok Ads') {
// console.log($.html())
// console.log($('table.templateContainer').html())
// console.log($('table.templateContainer tbody').html())
let code = $('table.templateContainer tbody').find('tr').eq(6).text()
code = code.replace(/\ +/g, "");
code = code.replace(/[\r\n]/g, "");
global.code = code
console.log(code);
// $('table.templateContainer tbody').find('tr').each(function(i, elem) {
// console.log(i)
// //console.log(elem)
// })
}
}
// if (data.type === 'attachment') { //附件
// console.log("邮件附件信息>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
// console.log("附件名称:" + data.filename); //打印附件的名称
// data.content.pipe(fs.createWriteStream(data.filename)); //保存附件到当前目录下
// data.release();
// }
});
});
msg.once('end', function() {
console.log(seqno + '完成');
});
});
f.once('error', function(err) {
console.log('抓取出现错误: ' + err);
});
f.once('end', function() {
console.log('所有邮件抓取完成!');
imap.end();
});
});
});
});
imap.once('error', function(err) {
console.log(err);
});
imap.once('end', function() {
reg(global.code)
console.log('关闭邮箱', global.user, global.code);
});
imap.connect();
})();
us
最新推荐文章于 2024-04-08 15:17:37 发布