当前位置:网站首页>Puppeter connects to the existing Chrome browser
Puppeter connects to the existing Chrome browser
2022-07-06 22:34:00 【User 6256742】
Preface
Puppeteer It is a very popular headless browser and has received a lot recently star. The main function is to use and install Chromium Start a browser to simulate user operation , But this browser can be said to be one-time, unable to cache information , Many times we want to Puppeteer You can reuse locally launched browsers . After searching several articles, summarize the correct usage :
Use
1. In order to ensure a smooth link, we need to set Chrome The startup port of the browser
Right click the shortcut to set the content in the target : Add --remote-debugging-port=9222
2. Write program configuration puppeteer To configure
const axios = require('axios');
const puppeteer=require('puppeteer');
(async()=>{
let wsKey = await axios.get('http://localhost:9222/json/version');
let browser=await puppeteer.connect({
browserWSEndpoint: wsKey.data.webSocketDebuggerUrl,
defaultViewport:null
});
let page=await browser.newPage()
await page.goto('https://blogweb.cn');
// await page.close()
// await browser.disconnect()
})()
Explain
Use axios Get the corresponding link (http://localhost:9222/json/version) The communication configuration of is passed in puppeteer To configure ( The port number in the link needs to be and Chrome The port number in the target path corresponds to )
The following is the basic configuration of creating page scrolling and page Jump
summary
- modify Chrome Fixed port number
- In the configuration browser Request the corresponding connection before configuration webSocket To configure
- take webSocket Of key Put it into the corresponding configuration
边栏推荐
- MySQL约束的分类、作用及用法
- How to confirm the storage mode of the current system by program?
- 如何用程序确认当前系统的存储模式?
- Heavyweight news | softing fg-200 has obtained China 3C explosion-proof certification to provide safety assurance for customers' on-site testing
- 二分图判定
- Inno setup packaging and signing Guide
- [Digital IC hand tearing code] Verilog burr free clock switching circuit | topic | principle | design | simulation
- hdu 5077 NAND(暴力打表)
- Export MySQL table data in pure mode
- (18) LCD1602 experiment
猜你喜欢
自制J-Flash烧录工具——Qt调用jlinkARM.dll方式
在IPv6中 链路本地地址的优势
Memorabilia of domestic database in June 2022 - ink Sky Wheel
CocosCreator+TypeScripts自己写一个对象池
0 basic learning C language - interrupt
Attack and defense world miscall
关于声子和热输运计算中BORN电荷和non-analytic修正的问题
Senior soft test (Information System Project Manager) high frequency test site: project quality management
自定义 swap 函数
MySQL----初识MySQL
随机推荐
Dealing with the crash of QT quick project in offscreen mode
Spatial domain and frequency domain image compression of images
uniapp设置背景图效果demo(整理)
视图(view)
go多样化定时任务通用实现与封装
GD32F4XX串口接收中断和闲时中断配置
在IPv6中 链路本地地址的优势
rust知识思维导图xmind
【LeetCode】19、 删除链表的倒数第 N 个结点
pytorch_ Yolox pruning [with code]
【无标题】
Leetcode exercise - Sword finger offer 26 Substructure of tree
AdaViT——自适应选择计算结构的动态网络
【编译原理】做了一半的LR(0)分析器
MySQL数据库基本操作-DML
Improving Multimodal Accuracy Through Modality Pre-training and Attention
MySQL ---- first acquaintance with MySQL
Installation and use of labelimg
qt quick项目offscreen模式下崩溃的问题处理
将MySQL的表数据纯净方式导出