当前位置:网站首页>Puppeteer连接已有Chrome浏览器
Puppeteer连接已有Chrome浏览器
2022-07-06 15:10:00 【用户6256742】
前言
Puppeteer是一个非常火爆的无头浏览器并在最近得到非常多的star。主要功能是使用安装的Chromium启动一个浏览器来模拟用户操作,但是这个浏览器可以说是一次性的无法缓存信息,很多时候我们希望Puppeteer可以复用本地已启动的浏览器。在查找多篇文章后总结出正确的使用方法:
使用
1.为了保证顺利链接我们需要设置Chrome浏览器的启动端口
右键快捷方式设置目标中的内容:在最后空格后添加 --remote-debugging-port=9222
2.编写程序配置puppeteer配置
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()
})()讲解
使用axios获取对应链接(http://localhost:9222/json/version)的通信配置传入puppeteer配置(链接中的端口号需要和Chrome目标路径中的端口号对应)
后面就是基本的创建页面页面滚动以及页面跳转的配置了
总结
- 修改Chrome固定端口号
- 在配置browser配置前请求对应的连接获取webSocket配置
- 将webSocket的key放入对应的配置中
边栏推荐
- 如何实现文字动画效果
- Leetcode question brushing (XI) -- sequential questions brushing 51 to 55
- uniapp滑动到一定的高度后固定某个元素到顶部效果demo(整理)
- return 关键字
- 做国外LEAD2022年下半年几点建议
- 基于 QEMUv8 搭建 OP-TEE 开发环境
- Anaconda installs third-party packages
- General implementation and encapsulation of go diversified timing tasks
- 二叉(搜索)树的最近公共祖先 ●●
- signed、unsigned关键字
猜你喜欢

3DMAX assign face map

自定义 swap 函数

Management background --1 Create classification

数据处理技巧(7):MATLAB 读取数字字符串混杂的文本文件txt中的数据

Seata aggregates at, TCC, Saga and XA transaction modes to create a one-stop distributed transaction solution

第3章:类的加载过程(类的生命周期)详解

2022年6月国产数据库大事记-墨天轮

Mise en place d'un environnement de développement OP - tee basé sur qemuv8
![[leetcode] 19. Delete the penultimate node of the linked list](/img/ab/25cb6d6538ad02d78f7d64b2a2df3f.png)
[leetcode] 19. Delete the penultimate node of the linked list

Seata聚合 AT、TCC、SAGA 、 XA事务模式打造一站式的分布式事务解决方案
随机推荐
基於 QEMUv8 搭建 OP-TEE 開發環境
NetXpert XG2帮您解决“布线安装与维护”难题
云原生技术--- 容器知识点
pytorch_ Yolox pruning [with code]
重磅新闻 | Softing FG-200获得中国3C防爆认证 为客户现场测试提供安全保障
Inno setup packaging and signing Guide
Export MySQL table data in pure mode
CocosCreator+TypeScripts自己写一个对象池
MySQL约束的分类、作用及用法
i. Mx6ull build boa server details and some of the problems encountered
Aardio - 封装库时批量处理属性与回调函数的方法
2500 common Chinese characters + 130 common Chinese and English characters
Heavyweight news | softing fg-200 has obtained China 3C explosion-proof certification to provide safety assurance for customers' on-site testing
Chapter 4: talk about class loader again
Learn the principle of database kernel from Oracle log parsing
新手程序员该不该背代码?
return 关键字
Notes de développement du matériel (10): flux de base du développement du matériel, fabrication d'un module USB à RS232 (9): création de la Bibliothèque d'emballage ch340g / max232 SOP - 16 et Associa
中国固态氧化物燃料电池技术进展与发展前景报告(2022版)
What are the interface tests? What are the general test points?