Skip to content

Instantly share code, notes, and snippets.

@paps
Last active Nov 15, 2017
Embed
What would you like to do?
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)
})
@yairEO
Copy link

yairEO commented Sep 19, 2017

where do you put this code.. on a runnable Node file?
why would this even open Chrome?

@gregorydgarcia
Copy link

gregorydgarcia commented Nov 15, 2017

@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