Puppeteer

Opening local html file using puppeteer

你说的曾经没有我的故事 提交于 2019-11-30 13:43:05
问题 Is it possible to open local html file with headless chrome using puppeteer (without web server)? I could only gate it to work against local server. I could see setContent() api and goto() api and page.goto: did not work with local file or file:// too. page.setContent: is for html string 回答1: I just did a test locally (you can see I did this on windows) and puppeteer happily opened my local html file using page.goto and a full file url, and saved it as a pdf: 'use strict'; const puppeteer =

How to download file with puppeteer using headless: true?

白昼怎懂夜的黑 提交于 2019-11-30 12:50:34
问题 I've been running the following code in order to download a csv file from the website http://niftyindices.com/resources/holiday-calendar : const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({headless: true}); const page = await browser.newPage(); await page.goto('http://niftyindices.com/resources/holiday-calendar'); await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: '/tmp'}) await page.click('#exportholidaycalender'

Puppeteer wait page load after form submit

江枫思渺然 提交于 2019-11-30 10:42:44
I submit a form using the following code and i want Puppeteer to wait page load after form submit. await page.click("button[type=submit]"); //how to wait until the new page loads before taking screenshot? // i don't want this: // await page.waitFor(1*1000); //← unwanted workaround await page.screenshot({path: 'example.png'}); How to wait for page load with puppeteer? You can wait for navigation asynchronously to avoid getting null on redirection, await Promise.all([ page.click("button[type=submit]"), page.waitForNavigation({ waitUntil: 'networkidle0' }), ]); This will help you if the page

Opening local html file using puppeteer

坚强是说给别人听的谎言 提交于 2019-11-30 08:25:10
Is it possible to open local html file with headless chrome using puppeteer (without web server)? I could only gate it to work against local server. I could see setContent() api and goto() api and page.goto: did not work with local file or file:// too. page.setContent: is for html string I just did a test locally (you can see I did this on windows) and puppeteer happily opened my local html file using page.goto and a full file url, and saved it as a pdf: 'use strict'; const puppeteer = require('puppeteer'); (async() => { const browser = await puppeteer.launch(); const page = await browser

开源一文多发平台ArtiPub,让文章随处可阅

醉酒当歌 提交于 2019-11-30 05:48:33
背景 很多优秀的程序员和技术人员喜欢写技术文章和技术博客,通过这样的方式分享传播知识和经验,扩大自己的知名度和影响力,吸引粉丝关注,甚至有些技术博主还通过写文章来获取广告收入,很多优秀的博主还通过这种方法获得了出版书的机会以及工作机会。因此,写技术文章是一件非常值得投入的事情,帮助了自己,也让大众受益。 但是,写技术文章通常也很耗时,特别是一些优质文章,不仅需要旁征博引、构思文章结构、照顾读者受众,还需要做很多前期工作,例如搭建环境、写demo代码、测试代码等等。一篇优质技术文章通常需要3-6个小时来完成。然而,花了很多时间来写文章,最终发布出来的文章得不到很多人的关注是一件相当令人沮丧的事情。我们认为,优质文章值得获取关注和传播,让更多的技术工作者通过阅读文章获取知识获益。 每个技术博主都有自己喜欢的技术媒体平台,例如掘金、CSDN、微信公众号等等。很多技术博主也喜欢将文章发布在不同的平台上,寻求最大的关注度,同时也防止自己辛辛苦苦写的文章被别人复制粘贴盗版过去。然而,在多个平台上发文是一件麻烦的事情:博主需要同时登陆多个媒体平台,将自己的文章复制一个一个粘贴过去;更麻烦的是,有些平台只支持Markdown,有些平台只支持富文本,博主需要在这两者之间来回转换,这增加了工作量。 一文多发平台ArtiPub就解决了这样的问题

How to download file with puppeteer using headless: true?

我怕爱的太早我们不能终老 提交于 2019-11-30 05:06:46
I've been running the following code in order to download a csv file from the website http://niftyindices.com/resources/holiday-calendar : const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({headless: true}); const page = await browser.newPage(); await page.goto('http://niftyindices.com/resources/holiday-calendar'); await page._client.send('Page.setDownloadBehavior', {behavior: 'allow', downloadPath: '/tmp'}) await page.click('#exportholidaycalender'); await page.waitFor(5000); await browser.close(); })(); with headless: false it works, it downloads

puppeteer page.evaluate querySelectorAll return empty objects

两盒软妹~` 提交于 2019-11-30 03:16:08
问题 I am trying puppeteer, this is a sample code you can run it on https://try-puppeteer.appspot.com/ the problem is this code is returning an array of empty objects [{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}] Am I doing any mistake ? const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://reddit.com/'); let list = await

how to manage log in session through headless chrome?

て烟熏妆下的殇ゞ 提交于 2019-11-30 01:51:33
I need to make scraper to: open headless browser, go to url , log in (there is steam oauth), fill some inputs, click 2 buttons problem is every new instance of headless browser clears my login session, and then i need to login again and again...how to save it through instances? for example using puppeteer with headless chrome or how can i open already logged in chrome headless instance? if i already log in in my main chrome window Ramiro In puppeter you have access to the session cookies through page.cookies() . So once you log in, you could get every cookie and save it in a json file using

How to specify browser language in Puppeteer

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 01:26:59
问题 I would like to launch a Google Chrome browser with language Spanish es using Puppeteer. I've tried puppeteer.launch(args:['--lang=es',...],...) but it didn't work. I've tried passing the environment variable LANGUAGE=es mocha puppeteer-test.js but it didn't work. I've tried using the userDataDir option and passing a folder with a Preferences file a { "intl": { "accept_languages": "es" } } but the browser Settings - Languages still don't show Spanish and neither does window.navigator

inject jquery into puppeteer page

被刻印的时光 ゝ 提交于 2019-11-30 01:12:38
I'm trying to inject jquery into my puppeteer page because document.querySelector doesn't cut it for me: async function inject_jquery(page){ await page.evaluate(() => { var jq = document.createElement("script") jq.src = "https://code.jquery.com/jquery-3.2.1.min.js" document.querySelector("head").appendChild(jq) }) const watchDog = page.waitForFunction('window.jQuery !== undefined'); await watchDog; } The result is it mostly times out. Does anyone have a solution? I have used page.addScriptTag to inject js files. ... await page.addScriptTag({url: 'https://code.jquery.com/jquery-3.2.1.min.js'})