Puppeteer

How to detect the request come from Puppeteer?

北战南征 提交于 2020-11-29 03:10:23
问题 I wonder whether or not exists some flag or tag that the website can use it to detect the request came from Puppeteer? When I ran my code based on Puppeteer to visit the target website, I found that the website seems to know the request was made by Puppeteer. How can it do? 回答1: If you are running the puppeteer and would like to pass some information to the website to catch your crawling, the best way to do so would be to set a custom user agent: const browser = await puppeteer.launch({ args:

How to detect the request come from Puppeteer?

被刻印的时光 ゝ 提交于 2020-11-29 03:08:55
问题 I wonder whether or not exists some flag or tag that the website can use it to detect the request came from Puppeteer? When I ran my code based on Puppeteer to visit the target website, I found that the website seems to know the request was made by Puppeteer. How can it do? 回答1: If you are running the puppeteer and would like to pass some information to the website to catch your crawling, the best way to do so would be to set a custom user agent: const browser = await puppeteer.launch({ args:

puppeteer 用cookie登录osc批量修改文章

自闭症网瘾萝莉.ら 提交于 2020-11-27 09:48:49
第一种是安装chrome-cookies-secure库, 但是只有在mac和linux上可行, win10安装失败 const chrome = require('chrome-cookies-secure'); const puppeteer = require('puppeteer'); const url = 'https://my.oschina.net/ahaoboy'; chrome.getCookies(url, 'puppeteer', function(err, cookies) { if (err) { console.log(err, 'error'); return } console.log(cookies, 'cookies'); callback(cookies); } ) // e.g. 'Profile 2' } // find profiles at ~/Library/Application Support/Google/Chrome getCookies(async (cookies) => { const browser = await puppeteer.launch({ headless: false }); const page = await browser.newPage(); await page.setCookie(..

小程序自动化测试优化之wx API拦截

那年仲夏 提交于 2020-11-13 11:46:37
随着小程序越来越被广泛使用,我们前端的开发工作也从单纯的web开发,扩大到web+小程序的跨端开发。为了提高研发效率,越来越多的web模块需要迁移、更新,兼容小程序以实现跨端复用。而这些模块也会跟随业务进行迭代和版本更新,这时候,我们就需要有良好的测试来保障各端模块的可靠性。 由于我们将许多已有的web模块迁移到小程序,web端的测试相对已经比较完备了。因此我们需要考虑的是: 如何快速的将已有的web用例迁移到小程序 针对新模块,如何快速编写两端用例。 (我们在web端使用的主要是Puppeteer和Jest的搭配。) 可直接移步最终方案 测试模块类型 我们目前的模块主要是以下三种类型: 与环境无关的逻辑层模块 与环境关联的逻辑层模块 与环境关联的UI组件模块 类型1的模块由于不受环境限制,可与web共用单元测试,无需额外的测试用例开发。 类型3的模块,由于小程序与web端差异较大,比较难实现复用(目前我们的web UI层主要基于React,小程序使用原生开发,同时配合kbone进行部分页面的同构开发)。 我们这里主要针对类型2的模块进行测试用例的迁移。 小程序端测试工具选择 小程序官方目前提供了两种工具来支持小程序测试: 组件单元测试 提供了一个测试工具集以支持自定义组件在 nodejs 单线程中运行。 小程序自动化 为开发者提供了一套通过外部脚本操控小程序的方案。