当前位置:网站首页>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
边栏推荐
- extern关键字
- Spatial domain and frequency domain image compression of images
- Plafond du tutoriel MySQL, bien collecté, regardez lentement
- MySQL数据库基本操作-DML
- pytorch_ Yolox pruning [with code]
- const关键字
- Unity3d minigame-unity-webgl-transform插件转换微信小游戏报错To use dlopen, you need to use Emscripten‘s...问题
- 【踩坑合辑】Attempting to deserialize object on CUDA device+buff/cache占用过高+pad_sequence
- OpenCV VideoCapture. Get() parameter details
- Applet system update prompt, and force the applet to restart and use the new version
猜你喜欢
随机推荐
Report on technological progress and development prospects of solid oxide fuel cells in China (2022 Edition)
labelimg的安装与使用
go多样化定时任务通用实现与封装
MySQL ---- first acquaintance with MySQL
POJ 1258 Agri-Net
Build op-tee development environment based on qemuv8
Crawler obtains real estate data
2022-07-05 use TPCC to conduct sub query test on stonedb
Lora sync word settings
2022-07-05 stonedb sub query processing parsing time analysis
自制J-Flash烧录工具——Qt调用jlinkARM.dll方式
【数字IC手撕代码】Verilog无毛刺时钟切换电路|题目|原理|设计|仿真
每日一题:力扣:225:用队列实现栈
BasicVSR_PlusPlus-master测试视频、图片
config:invalid signature 解决办法和问题排查详解
Aardio - 通过变量名将变量值整合到一串文本中
视图(view)
The SQL response is slow. What are your troubleshooting ideas?
Const keyword
China 1,4-cyclohexanedimethanol (CHDM) industry research and investment decision-making report (2022 Edition)