Puppeteer

Puppeteer爬虫实战(三)

淺唱寂寞╮ 提交于 2020-08-16 06:06:35
本篇文章针对大家熟知的技术站点作为目标进行技术实践。 确定需求   访问目标网站并按照筛选条件(关键词、日期、作者)进行检索并获取返回数据中的目标数据。进行技术拆分如下: 打开目标网站 找到输入框元素输入关键词,找到日期元素设置日期,找到搜索按钮触发搜索动作 解析搜索返回的html元素构造目标数据 将目标数据保存 编写代码 'use strict'; const puppeteer = require('puppeteer'); const csv = require('fast-csv'); const fs = require('fs'); (async () => { const startUrl = 'https://www.infoq.cn/'; const keyWord = 'CQRS'; const browser = await puppeteer.launch({ slowMo: 100, // 放慢速度 headless: false, // 是否有头 defaultViewport: {// 界面设置 width: 1820, height: 1080, }, ignoreHTTPSErrors: false, // 忽略 https 报错 args: ['--start-maximized', '--no-sandbox', '--disable

CukeTest+Puppeteer的Web自动化测试(二)

依然范特西╮ 提交于 2020-08-15 13:55:52
  上一篇我们讲了CukeTest+Puppeteer的相关理论知识,带大家认识熟悉了CukeTest如何运行与如何编写剧本,Puppeteer大体的理论体系与如何结合使用,但一直没有给大家进行上手实战操作。这一篇,我就带大家一起来实战燥起来~~~ 测试页面以百度首页为例,我们用CukeTest+Puppeteer编写功能测试Demo,将上篇讲的相关知识点结合起来练手。 CukeTest官方文档: http://www.cuketest.com/zh-cn/ Puppeteer官方文档: https://zhaoqize.github.io/puppeteer-api-zh_CN/ 一、实例1 功能测试:参数化形式打开多个网页   1、打开CukeTest我们来新建一个空项目,安装Node和Puppeteer,注意(两者版本兼容问题),上文中已提到过的。   2、编辑剧本相关参数   3、编写剧本对应的脚本   4、运行 如下图 剧本的文本如下 # language: zh-CN 功能: 百度首页 打开百度首页 @openPage 场景大纲: 页面打开 假如打开百度首页 "<param1>" @pageOne 例子: | param1 | | https: //www.baidu.com/ | | https: //www.runoob.com/ | @pageTwo 例子: |

使用docker puppeteer api 接口返回

梦想与她 提交于 2020-08-14 17:33:56
安装 安装docker,使用模拟手机访问 mkdir /docker/puppeteer-renderer/src 目录中的代码有 index.js, renderer.js,wait-for-animations.js ,代码依次是 'use strict' const express = require('express') const qs = require('qs') const { URL } = require('url') const contentDisposition = require('content-disposition') const createRenderer = require('./renderer') const port = process.env.PORT || 3000 const app = express() let renderer = null // Configure. app.set('query parser', s => qs.parse(s, { allowDots: true })) app.disable('x-powered-by') // Render url. app.use(async (req, res, next) => { let { url, type, filename, ...options }

Puppeteer笔记(一):Puppeteer简介

扶醉桌前 提交于 2020-08-12 17:07:55
一、Puppeteer简介   Puppeteer是NPM库,它提供了NodeJS高级API来控制Chrome。Puppeteer 默认以无头(无界面)方式运行,但也可以配置为运行有界面的Chrome。   Puppeteer 提供了一系列 API,通过 Chrome DevTools Protocol 协议控制 Chromium/Chrome 浏览器的行为 二、什么是Headless Chrome   (1)在无界面的环境中运行 Chrome   (2)通过命令行或者程序语言操作 Chrome   (3)无需人的干预,运行更稳定   (4)在启动 Chrome 时添加参数 --headless,便可以 headless 模式启动 Chrome 三、Puppeteer 结构   API分层结构,反映了浏览器结构 Puppeteer: 使用DevTools协议与浏览器进行通信 Browser:对应一个浏览器实例,一个 Browser 可以包含多个 BrowserContext、 BrowserContext: 对应浏览器一个上下文会话,就像我们打开一个普通的 Chrome 之后又打开一个隐身模式的浏览器一样,BrowserContext 具有独立的 Session(cookie 和 cache 独立不共享),一个 BrowserContext 可以包含多个 Page Page

618前端竞品分析研究(互动篇)

梦想的初衷 提交于 2020-08-12 08:45:06
作者:吉玉 智能化测试 在互动中经常需要维护 大量的状态 ,对这些状态进行 测试验证成本较高 ,尤其是当有功能变动需要回归测试的时候。为了降低开发测试的成本,在这方面使用 强化学习模拟用户行为 ,在两个方面提效: mock接口 :将学习过程中的状态作为服务接口的测试数据; 回归测试 :根据mock接口数据回溯到特定状态,Puppeteer根据强化学习触发前端操作,模拟真实用户行为; 什么是强化学习呢? 强化学习是机器学习的一个领域,它强调如何基于环境行动,获取最大化的预期利益。强化学习非常适用于近几年比较流行的电商互动机制:做任务/做游戏 -> 得到不同的奖励值 -> 最终目标大奖,在这类型的互动游戏中,奖励是可预期的,用户的目标是使得自己的奖励最大化。这个过程可以抽象为马尔科夫决策模型:玩家(agent)通过不同的交互行为(action),改变游戏(environment)的状态(state),反馈给玩家不同的奖励 (reward);这个过程不断循环迭代, 玩家的最终目标是奖励最大化。 接下来,我们使用比较简单的Q-learning,来实现类似的智能化测试目的。 Q-learning 对于不同状态下,Q-learning的Q(s,a)表示在某一个时刻的s状态下,采取动作a可以得到的收益期望,算法的主要思想是将state和ation构建一张Q-table来存储Q值

CukeTest+Puppeteer的Web自动化测试

我只是一个虾纸丫 提交于 2020-08-11 09:36:28
测试页面以百度首页为例,我们用CukeTest+Puppeteer编写功能测试Demo,将上篇讲的相关知识点结合起来练手。 CukeTest官方文档: http://www.cuketest.com/zh-cn/ Puppeteer官方文档: https://zhaoqize.github.io/puppeteer-api-zh_CN/ 一、实例1 功能测试:参数化形式打开多个网页 1、打开CukeTest我们来新建一个空项目,安装Node和Puppeteer,注意(两者版本兼容问题),上文中已提到过的。 2、编辑剧本相关参数 3、编写剧本对应的脚本 4、运行 如下图 剧本的文本如下 # language: zh-CN 功能: 百度首页 打开百度首页 @openPage 场景大纲: 页面打开 假如打开百度首页 "<param1>" @pageOne 例子: | param1 | | https://www.baidu.com/ | | https://www.runoob.com/ | @pageTwo 例子: | param1 | | https://www.csdn.net/ | | https://www.cnblogs.com/ | @baiduSearch 场景: 百度首页搜索 打开百度首页,搜索 'puppeteer',百度查询并截图保存结果 假如打开百度首页

codeceptjs tests 'before each' hook error fails to launch chrome. tests were working fine a week ago

拥有回忆 提交于 2020-08-10 18:51:17
问题 I asked this question several months ago here but the solution was obviously not helpful because here I am again with the exact same problem. in that link I was told to change my image from node:latest to node:13 . this no longer fixes the problem. I have tried every version of node and none work. I have tried using premade images of puppeteer/codeceptjs but that does not work. here's the problem: 4 months ago I coded a bunch of tests. they worked fine so i set them up on gitlab to run

codeceptjs tests 'before each' hook error fails to launch chrome. tests were working fine a week ago

谁说胖子不能爱 提交于 2020-08-10 18:51:11
问题 I asked this question several months ago here but the solution was obviously not helpful because here I am again with the exact same problem. in that link I was told to change my image from node:latest to node:13 . this no longer fixes the problem. I have tried every version of node and none work. I have tried using premade images of puppeteer/codeceptjs but that does not work. here's the problem: 4 months ago I coded a bunch of tests. they worked fine so i set them up on gitlab to run

Puppeteer笔记(四):Puppeteer模拟键盘

不想你离开。 提交于 2020-08-10 18:50:04
一、Puppeteer模拟键盘 1、keyboard.down(key[,options]) 2、keyboard.press(key[,options]) 3、keyboard.type(text,options) 4、keyboard.up(key]) 二、上手实例Demo   Puppeteer模拟键盘,功能测试:打开百度首页,输入"hello world!",删除world,并模拟键盘按下”A"。 1 const puppeteer = require('puppeteer' ); 2 async function keyboard() { 3 // 创建一个Browser浏览器实例,并设置相关参数 4 const browser = await puppeteer.launch({ 5 headless: false , 6 defaultViewport: null , 7 args: ['--start-maximized' ], 8 ignoreDefaultArgs: ['--enable-automation' ] 9 }); 10 // 创建一个Page实例 11 const page = await browser.newPage(); 12 // 打开百度首页 13 await page.goto("https://www.baidu.com" ); 14

if URL contains function in puppeteer

元气小坏坏 提交于 2020-08-09 07:03:06
问题 So I am trying to have my code do something if the URL contains this: https://kith.com/throttle/queue? After the '?' there can be anything, so I only want it to identify 'https://kith.com/throttle/queue?' I am using puppeteer and want it to work like this: If the URL contains 'https://kith.com/throttle/queue?' then wait until it passes the queue (page.waitForNavigation({ waitUntil: 'networkidle2' }) would work for waiting until it's through the queue Else (If the URL doesn't contain that): do