We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
yarn add puppeteer # OR yarn add puppeteer-core
puppeteer-core 版本不会额外下载一个 Chromium (安装贼慢),同时会忽略所有 PUPPETEER_ * env 变量
puppeteer-core
Chromium
PUPPETEER_ * env
puppeteer vs puppeteer-core
import puppeteer from 'puppeteer-core' ;(async () => { try { // 打开浏览器 const browser = await puppeteer.launch({ // 手动指定浏览器执行文件地址(puppeteer-core 版本必须手动指定) executablePath: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome', // 是否以无头模式运行浏览器 headless: false }) // 打开新的标签页 const page = await browser.newPage() // 在页面加载前修改某个属性 await page.evaluateOnNewDocument(() => { /** * 修改 navigator.webdriver 属性,防止反爬虫 * (如 boss 直聘会检测 puppeteer 一直 debug) **/ Object.defineProperty(navigator, 'webdriver', { get: () => undefined }) }) // 跳转到指定 url await page.goto('https://github.com/maomao1996') // 获取页面 html const html = await page.content() // 获取指定 HTMLElement 对象( document.querySelector ) const nameEl = await page.$('.p-name.vcard-fullname') // 获取指定 HTMLElement 的文本 const nameText = await page.$eval( '.p-name.vcard-fullname', (el) => el.innerText ) console.log('nameText', nameText) // 关闭标签页 await page.close() // 关闭浏览器 await browser.close() } catch (error) { console.log('error', error) } })()
Puppeteer Github Puppeteer 中文文档
The text was updated successfully, but these errors were encountered:
No branches or pull requests
puppeteer 学习笔记
安装
yarn add puppeteer # OR yarn add puppeteer-core
puppeteer-core
版本不会额外下载一个Chromium
(安装贼慢),同时会忽略所有PUPPETEER_ * env
变量puppeteer vs puppeteer-core
API 用法记录
相关资料
Puppeteer Github
Puppeteer 中文文档
The text was updated successfully, but these errors were encountered: