Posts How I replicated an $86 million project in 57 lines of code
Post
Cancel

How I replicated an $86 million project in 57 lines of code

https://medium.freecodecamp.org/how-i-replicated-an-86-million-project-in-57-lines-of-code-277031330ee9

using nodejs with http://www.horsemanjs.org/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// src - https://gist.github.com/taitems/7c56e6e1b51906f9158281bda3839545#file-plate-snitch-js
// Open form and submit enquire for `rego`
function getInfo(rego) {
	horseman
	  .userAgent('Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0')
	  .open(url)
	  .type('#registration-number-ctrl input[type=text]', rego)
	  .click('.btn-holder input')
	  .waitForSelector('.ctrl-holder.ctrl-readonly')
	  .html()
	  .then(function(body) {
	  	console.log(processInfo(body, rego));
	    return horseman.close();
	  });
}

// Scrape the results for key info
function processInfo(html, rego) {
	var $ = cheerio.load(html);
	var vehicle = $('label.label').filter(function() {
	  return $(this).text().trim() === 'Vehicle:';
	}).next().text().trim();

	var stolen = $('label.label').filter(function() {
	  return $(this).text().trim() === 'Stolen status:';
	}).next().text().trim();

	var registration = $('label.label').filter(function() {
	  return $(this).text().trim() === 'Registration status & expiry date:';
	}).next().text().trim();

	return {
		rego,
		vehicle,
		stolen,
		registration
	};
}

origin - http://www.pipiscrew.com/?p=10062 how-i-replicated-an-86-million-project-in-57-lines-of-code

This post is licensed under CC BY 4.0 by the author.
Contents

Trending Tags