Nick.js test

by mhouser_nowmediagroup

Babel + JSX

const Nick = require("nickjs")
const nick = new Nick()

;(async () => {
	const tab = await nick.newTab()
	await tab.open("https://attorneys.lawinfo.com/california/san-diego/viewall/#viewall")
	await tab.untilVisible("#viewall") // Make sure we have loaded the page
	await tab.inject("../injectables/jquery-3.0.0.min.js") // We're going to use jQuery to scrape
	const lawerTitles = await tab.evaluate((arg, callback) => {
		// Here we're in the page context. It's like being in your browser's inspector tool
		const data = []
		$(".listing-card").each((index, element) => {
			data.push({
				title: $(element).find(".directory_phone > span").text(),
			})
		})
		callback(null, data)
	})
	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 = []
		$(".listing-card").each((index, element) => {
			data.push({
				title: $(element).find(".directory_phone > span").text(),
			})
		})
		callback(null, data)
	})
	console.log(JSON.stringify(hackerNewsLinks, null, 2))
})()
.then(() => {
	console.log("Job done!")
	nick.exit()
})
.catch((err) => {
	console.log(`Something went wrong: ${err}`)
	nick.exit(1)
})


/*

const Nick = require("nickjs")
const nick = new Nick()

;(async () => {
	const tab = await nick.newTab()
	await tab.open("yahoo.com")
	await tab.untilVisible("#qs-issue") // Make sure we have loaded the page
	await tab.inject("../injectables/jquery-3.0.0.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 = []
		$("h3[class^='Mb']").each((index, element) => {
			data.push({
				title: $(element).find("span").text(),
			})
		})
		callback(null, data)
	})
	console.log(JSON.stringify(hackerNewsLinks, null, 2))
})()
.then(() => {
	console.log("Job done!")
	nick.exit()
})
.catch((err) => {
	console.log(`Something...