Skip to content
New issue

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

Feature request: original HTML content ('View Page Source') #749

Closed
datasunny opened this issue Sep 11, 2017 · 4 comments
Closed

Feature request: original HTML content ('View Page Source') #749

datasunny opened this issue Sep 11, 2017 · 4 comments

Comments

@datasunny
Copy link

New feature request: adding a new method to retrieve original HTML content of a web page (before Javascript rendering), just like in Chrome browser, right click mouse and choose 'View Page Source'.

@ebidel
Copy link
Contributor

ebidel commented Sep 11, 2017

How about this:

const puppeteer = require('puppeteer');

puppeteer.launch().then(async browser => {
  const page = await browser.newPage();
  const url = 'https://www.chromestatus.com/features';

  page.on('response', async resp => {
    if (resp.ok && resp.url === url) {
      console.log(await resp.text());
    }
  });

  await page.goto(url);

  browser.close();
});

Alternatively, you don't really need Puppeteer for this:

const https = require('https');
https.get('https://www.chromestatus.com/features', resp => {
  let data = '';
  resp.on('data', (chunk) => data += chunk);
  resp.on('end', () => console.log(data));
});

@aslushnikov
Copy link
Contributor

@datasunny: just use the main resource response to retrieve content:

const puppeteer = require('puppeteer');

puppeteer.launch().then(async browser => {
  const page = await browser.newPage();
  const response = await page.goto('https://www.chromestatus.com/features');
  console.log(await response.text());
  browser.close();
});

@ebidel
Copy link
Contributor

ebidel commented Sep 11, 2017

@aslushnikov nice. Forgot goto returns something :)

@datasunny
Copy link
Author

Thanks all for the lighting fast response!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants