npm i puppeteer
npm install puppeteer-extra-plugin-stealth
npm install puppeteer puppeteer-extra puppeteer-extra-plugin-stealth
//const puppeteer = require('puppeteer');
const puppeteer = require('puppeteer-extra')
// add stealth plugin and use defaults (all evasion techniques)
const StealthPlugin = require('puppeteer-extra-plugin-stealth')
puppeteer.use(StealthPlugin())
puppeteer.launch({
headless: false,
slowMo: 100,
}).then(async browser => {
console.log('Running tests..')
const page = await browser.newPage()
await page.goto('XXXXX')
const reg = ".*login.m.taobao.com.*"
const frameSelector = { url: new RegExp(reg) }
await pause(800);
page.frames().map(frame => {console.log("url:"+frame.url())});
//let frame = page.waitForFrame("body > div:nth-child(8) > iframe");
const targetFrameUrl = "XXXX"
const frame = await page.frames().find(frame=> frame.url().includes(targetFrameUrl));
////await frame.click("#login-form > div.login-blocks.switch-login-types > a");
const passwordLogin = frame.waitForSelector(".password-login-link");
await (await passwordLogin).click();
const username = frame.waitForSelector("#fm-login-id");
const password = frame.waitForSelector("#fm-login-password");
await (await username).type("XXX",{delay:200})
await (await password).type("XXX",{delay:220})
await pause(200);
const loginButton = frame.waitForSelector(".fm-button");
await (await loginButton).click();
await pause(500);
const okButton = frame.waitForSelector(".dialog-btn-ok");
await (await okButton).click({delay:120})
// const p = { x: 13, y: 23 };
/// await frame.locator(".login-blocks .block8").click({offset:p});
await pause(1500);
await browser.close()
console.log(`All done, check the screenshot. ✨`)
})
function pause(milliseconds) {
return new Promise((resolve) => {
setTimeout(resolve, milliseconds);
});
};
js 使用puppeteer 模拟登入,包括操作 iframe,模拟元素点击,输入 事件
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...