-
-
Save decodedmrq/0356cab14df6e8832d85310b1f9bdcae to your computer and use it in GitHub Desktop.
Revisions
-
anhdiepmmk revised this gist
Jan 11, 2020 . 1 changed file with 10 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.goto('https://example.com'); await page.screenshot({path: 'example.png'}); await browser.close(); })(); -
anhdiepmmk revised this gist
Jan 9, 2020 . 1 changed file with 12 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({}); const page = await browser.newPage(); await page.setViewport({width:1440, height:900, deviceScaleFactor: 2}); await page.goto('http://kenh14.vn/', { waitUntil: "networkidle2" }) await page.pdf({path: 'muong14.pdf', format: 'A4', printBackground: true, pageRanges: '1'}) await browser.close(); })(); -
anhdiepmmk revised this gist
Jan 6, 2020 . 2 changed files with 22 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ const puppeteer = require('puppeteer'); const cheerio = require('cheerio'); (async () => { const browser = await puppeteer.launch({headless: false, devtools: true}) const page = await browser.newPage() await page.goto('https://dantri.com.vn/') //https://github.com/cheeriojs/cheerio let content = await page.content(); var $ = cheerio.load(content); $('a').each(function(i, element){ let a = $(this) let title = a.text(); let url = a.attr('href'); console.log(`title: ${title} url: ${url}`) }); //await browser.close(); })() This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,6 +9,8 @@ "author": "", "license": "ISC", "dependencies": { "cheerio": "^1.0.0-rc.3", "puppeteer": "^2.0.0" } } -
anhdiepmmk revised this gist
Jan 6, 2020 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,6 +6,7 @@ const puppeteer = require('puppeteer'); await page.goto('http://www.nightmarejs.org/') const results = await page.evaluate(() => { console.log(document.documentElement.outerHTML) let items = document.querySelectorAll('a') let links = [] items.forEach((item) => { -
anhdiepmmk revised this gist
Jan 6, 2020 . 1 changed file with 11 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,11 @@ const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({headless: false}) const page = await browser.newPage() await page.goto('http://www.nightmarejs.org/') let html = await page.content(); console.log(html); await browser.close() })() -
anhdiepmmk revised this gist
Jan 6, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({headless: false}) const page = await browser.newPage() await page.goto('http://www.nightmarejs.org/') const results = await page.evaluate(() => { let items = document.querySelectorAll('a') -
anhdiepmmk revised this gist
Jan 6, 2020 . 1 changed file with 14 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,14 @@ { "name": "desktop", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "puppeteer": "^2.0.0" } } -
anhdiepmmk revised this gist
Jan 6, 2020 . No changes.There are no files selected for viewing
-
anhdiepmmk created this gist
Jan 6, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ const puppeteer = require('puppeteer'); (async () => { const browser = await puppeteer.launch({headless: false}) const page = await browser.newPage() await page.goto('https://dantri.com.vn/') const results = await page.evaluate(() => { let items = document.querySelectorAll('a') let links = [] items.forEach((item) => { links.push({ title: item.innerText, url: item.getAttribute('href'), }) }) return links; }); console.log(results) // Do what you want with the `results` await browser.close() })()