目标
用手机模式打开百度
主要学习以下知识点
方法名称 | 方法说明 |
---|---|
page.emulate | 为了支持模拟器,puppeteer 提供了一些设备的参数选项,可以通过 require(‘puppeteer/DeviceDescriptors’) 命令引入 |
详细api 可参考
https://blog.csdn/mengxiangxingdong/article/details/99237204
开始
本文章代码均在 上传在
https://gitee/hugo110/puppeteer-demo
效果图
1.代码
/**
模拟手机打开浏览器
*/
const devices = require('puppeteer/DeviceDescriptors') //引入手机设备ua 设置
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({headless: false})
const page = await browser.newPage()
await page.emulate(devices['iPhone X'])
await page.goto('http://www.baidu')
// await page.screenshot({path: 'c:/temp/baidu_iphone_X.png'})
})()
参考博客
https://zhaoqize.github.io/puppeteer-api-zh_CN/#?product=Puppeteer&version=v1.19.0&show=api-pageevalselector-pagefunction-args-1
发布评论