Advertisement
Flimbot

All suburbs of Australia

Feb 19th, 2020
784
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     var i, cheerio = require('cheerio'), request = require('request');
  2.     function scrapeSuburb(err, response, html) {
  3.         if (!err) {
  4.             var $ = cheerio.load(html);
  5.             $('.resultsList tbody tr').each(function () {
  6.                 var suburbDoc, suburbName = $(this).find('.second a').html().split(', ');
  7.  
  8.                if (suburbName && suburbName.length > 1) {
  9.                     suburbDoc = {
  10.                         postCode: $(this).find('.first a').html(),
  11.                         suburbName: suburbName[0],
  12.                         state: suburbName[1]
  13.                    };
  14.                    //do with it what you will
  15.                 }
  16.             });
  17.         }
  18.     }
  19.     for (i = 97; i < 123; i += 1) {
  20.         request(
  21.             'http://auspost.com.au/postcode/' + String.fromCharCode(i),
  22.             scrapeSuburb
  23.         );
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement