Skip to content

Instantly share code, notes, and snippets.

@paps
Last active November 15, 2017 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paps/85747469080cbcbd7c459f9d335fd030 to your computer and use it in GitHub Desktop.
Save paps/85747469080cbcbd7c459f9d335fd030 to your computer and use it in GitHub Desktop.
await tab.open("news.ycombinator.com")
await tab.untilVisible("#hnmain") // Make sure we have loaded the page
await tab.inject("https://code.jquery.com/jquery-3.2.1.min.js") // We're going to use jQuery to scrape
const hackerNewsLinks = await tab.evaluate((arg, callback) => {
// Here we're in the page context. It's like being in your browser's inspector tool
const data = []
$(".athing").each((index, element) => {
data.push({
title: $(element).find(".storylink").text(),
url: $(element).find(".storylink").attr("href")
})
})
callback(null, data)
})
@gregorydgarcia
Copy link

@yairEO he's using NickJS. Try something like:

import Nick from "nickjs"

const nick = new Nick()

nick.newTab(async (tab) => { 
	//
	//  Code goes here. 
	//
})
.then(() => {
	nick.exit(0)
})
.catch((err) => {
	console.log(err)
	nick.exit(1)
})

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