Skip to content

Instantly share code, notes, and snippets.

@bermanboris
Last active July 2, 2020 03:50
Show Gist options
  • Save bermanboris/1c24cb9fd77181c03989fe3b1be2a726 to your computer and use it in GitHub Desktop.
Save bermanboris/1c24cb9fd77181c03989fe3b1be2a726 to your computer and use it in GitHub Desktop.
PhantomJS usage in TypeScript ( Node.js )
// Usage:
//
// npm install phantom @types/phantom --save
// tsc --target "es6" ./phantomjs-example.ts
// node phantomjs-example.js
//
import * as phantom from "phantom";
async function getPageContent(url: string) {
const instance: phantom.PhantomJS = await phantom.create();
const page: phantom.WebPage = await instance.createPage();
const status: string = await page.open(url);
const content = await page.property('content');
console.log(content);
await instance.exit();
}
getPageContent("http://github.com");
@chusri
Copy link

chusri commented Jul 2, 2020

Thanks for your snippets.

btw, you can add the ts-node to run the .ts file directly.

ts-node phantomjs-example.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment