-
-
Save paps/85747469080cbcbd7c459f9d335fd030 to your computer and use it in GitHub Desktop.
This file contains 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 characters
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 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
where do you put this code.. on a runnable Node file?
why would this even open Chrome?