Node puppeteer implements website login monitoring idea sharing
This time I will share with you the ideas of node puppeteer for website login monitoring. What are the precautions for node puppeteer to implement website login monitoring? . The following is a practical case, let’s take a look.
puppeteer introduction
puppeteer is a node library developed by the Chrome team. It can control browser behavior through APIs, such as clicks and jumps. Transfer, refresh, execute js scripts in the console, etc. With this artifact, it is easy to write a crawler, automatically sign in, take screenshots of web pages, generate PDFs, and automate testing.
Simple example of puppeteer
The code comes from the official website:
const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch();//打开浏览器 const page = await browser.newPage();//打开一个空白页 await page.goto('https://example.com');//在地址栏输入网址并等待加载 await page.screenshot({path: 'example.png'});//截个图 await browser.close();//关掉浏览器 })();
Reading the above code, we can find that, 1. Code Each step in is an asynchronous operation, 2. Each step corresponds to an actual behavior of using the browser. Understanding these two points is of great help in using this library. In addition, the two most commonly used objects are the browser and page objects. There are a bunch of methods on the objects used to operate the two objects. Next, we will write a small demo for logging into the website.
Websites without verification code
For websites without verification code, basically enter the account number and password , the three steps of clicking to log in require the use of two methods of the page object: type is used to enter information in the input box, and click is used to click to log in. Let's take logging into Douban as an example:
const puppeteer = require('puppeteer'); const account = `123456@qq.com`; const password = `123456`; (async () => { const browser = await puppeteer.launch();//打开浏览器 const page = await browser.newPage();//打开一个空白页 await page.goto('https://www.douban.com/');//打开豆瓣网站 await page.type('#form_email', account); await page.type('#form_password', password); await page.click('.bn-submit'); await page.waitForNavigation({ waitUntil: 'load' });//等待页面加载出来,等同于window.onload await page.screenshot({path: 'example.png'});//截个图 await browser.close();//关掉浏览器 })();
Some people say, how do I know whether the login is successful? One way to debug is to use screenshots. If what you see is a verification code page , indicating that the login is not successful, there is another way like the following:
const browser = await puppeteer.launch({headless: false});//打开有界面的浏览器
After passing in headless: false, a browser interface will actually be opened, so that you can see where the code is executed in real time. . Next, let’s talk about what to do when you encounter a verification code.
Websites with verification codes
#When encountering websites with verification codes, you can set headless to false, use the interface to enter the verification code, and monitor the page at the same time Loading event, to achieve login, the code is as follows:
... await page.waitForNavigation({ waitUntil: 'load' });//等待页面加载出来,等同于window.onload //代码中监听跳转事件 if(page.url() === 'https://www.douban.com/accounts/login'){ //登录不成功 console.log('需要输入验证码'); //等待再一次跳转 while(true){ await page.waitForNavigation({ waitUntil: 'load' }) console.log(page.url()) if(page.url() === 'https://www.douban.com/'){ console.log('登录成功'); break; } } }
The overall idea is to write a loop, constantly monitor page jumps, until the browser jumps to the home page after successful login.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
How to use JS to implement the function of validating input numbers and retaining decimals
jQuery implements HTML page text box Fuzzy matching query (with code)
The above is the detailed content of Node puppeteer implements website login monitoring idea sharing. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

When you log in to someone else's steam account on your computer, and that other person's account happens to have wallpaper software, steam will automatically download the wallpapers subscribed to the other person's account after switching back to your own account. Users can solve this problem by turning off steam cloud synchronization. What to do if wallpaperengine downloads other people's wallpapers after logging into another account 1. Log in to your own steam account, find cloud synchronization in settings, and turn off steam cloud synchronization. 2. Log in to someone else's Steam account you logged in before, open the Wallpaper Creative Workshop, find the subscription content, and then cancel all subscriptions. (In case you cannot find the wallpaper in the future, you can collect it first and then cancel the subscription) 3. Switch back to your own steam

With the rapid development of social media, Xiaohongshu has become a popular platform for many young people to share their lives and explore new products. During use, sometimes users may encounter difficulties logging into previous accounts. This article will discuss in detail how to solve the problem of logging into the old account on Xiaohongshu, and how to deal with the possibility of losing the original account after changing the binding. 1. How to log in to Xiaohongshu’s previous account? 1. Retrieve password and log in. If you do not log in to Xiaohongshu for a long time, your account may be recycled by the system. In order to restore access rights, you can try to log in to your account again by retrieving your password. The operation steps are as follows: (1) Open the Xiaohongshu App or official website and click the "Login" button. (2) Select "Retrieve Password". (3) Enter the mobile phone number you used when registering your account

The solution to the Discuz background login problem is revealed. Specific code examples are needed. With the rapid development of the Internet, website construction has become more and more common, and Discuz, as a commonly used forum website building system, has been favored by many webmasters. However, precisely because of its powerful functions, sometimes we encounter some problems when using Discuz, such as background login problems. Today, we will reveal the solution to the Discuz background login problem and provide specific code examples. We hope to help those in need.

Thousands of ghosts screamed in the mountains and fields, and the sound of the exchange of weapons disappeared. The ghost generals who rushed over the mountains, with fighting spirit raging in their hearts, used the fire as their trumpet to lead hundreds of ghosts to charge into the battle. [Blazing Flame Bairen·Ibaraki Doji Collection Skin is now online] The ghost horns are blazing with flames, the gilt eyes are bursting with unruly fighting spirit, and the white jade armor pieces decorate the shirt, showing the unruly and wild momentum of the great demon. On the snow-white fluttering sleeves, red flames clung to and intertwined, and gold patterns were imprinted on them, igniting a crimson and magical color. The will-o'-the-wisps formed by the condensed demon power roared, and the fierce flames shook the mountains. Demons and ghosts who have returned from purgatory, let's punish the intruders together. [Exclusive dynamic avatar frame·Blazing Flame Bailian] [Exclusive illustration·Firework General Soul] [Biography Appreciation] [How to obtain] Ibaraki Doji’s collection skin·Blazing Flame Bailian will be available in the skin store after maintenance on December 28.

Recently, some friends have asked me how to log in to the Kuaishou computer version. Here is the login method for the Kuaishou computer version. Friends who need it can come and learn more. Step 1: First, search Kuaishou official website on Baidu on your computer’s browser. Step 2: Select the first item in the search results list. Step 3: After entering the main page of Kuaishou official website, click on the video option. Step 4: Click on the user avatar in the upper right corner. Step 5: Click the QR code to log in in the pop-up login menu. Step 6: Then open Kuaishou on your phone and click on the icon in the upper left corner. Step 7: Click on the QR code logo. Step 8: After clicking the scan icon in the upper right corner of the My QR code interface, scan the QR code on your computer. Step 9: Finally log in to the computer version of Kuaishou

How to log in to two devices with Quark? Quark Browser supports logging into two devices at the same time, but most friends don’t know how to log in to two devices with Quark Browser. Next, the editor brings users Quark to log in to two devices. Method graphic tutorials, interested users come and take a look! Quark Browser usage tutorial Quark how to log in to two devices 1. First open the Quark Browser APP and click [Quark Network Disk] on the main page; 2. Then enter the Quark Network Disk interface and select the [My Backup] service function; 3. Finally, select [Switch Device] to log in to two new devices.

Xiaohongshu has now been integrated into the daily lives of many people, and its rich content and convenient operation methods make users enjoy it. Sometimes, we may forget the account password. It is really annoying to only remember the account but not be able to log in. 1. How to log in if Xiaohongshu only remembers the account? When we forget our password, we can log in to Xiaohongshu through the verification code on our mobile phone. The specific operations are as follows: 1. Open the Xiaohongshu App or the web version of Xiaohongshu; 2. Click the "Login" button and select "Account and Password Login"; 3. Click the "Forgot your password?" button; 4. Enter your account number. Click "Next"; 5. The system will send a verification code to your mobile phone, enter the verification code and click "OK"; 6. Set a new password and confirm. You can also use a third-party account (such as

There are various reasons why you can't log in to your Microsoft account. Although it rarely happens, when it does, it can be frustrating. For example, in Windows 11, one of the reasons why this happens is because Microsoft Store built-in apps sometimes get corrupted and stop working properly. For example, this Reddit user ran into this problem, and other users came to the rescue with a simple solution that seemed to finally work. In order to be able to log back into your Microsoft account, all built-in Microsoft Store apps need to be reinstalled. Here's the thing. Open the Powershell application as administrator. Enter the following command: Get-Ap
