Created
February 23, 2020 23:43
-
-
Save slmcmahon/e9aa2baaba2c51b64482d3f8349ce780 to your computer and use it in GitHub Desktop.
U.S. State Codes
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
const axios = require('axios'); | |
const cheerio = require('cheerio'); | |
const url = 'https://www.infoplease.com/us/postal-information/state-abbreviations-and-state-postal-codes'; | |
axios.get(url).then(response => { | |
const $ = cheerio.load(response.data); | |
$('table.sgmltable tr').each((i, elem) => { | |
const children = $(elem).children() | |
const stateName = $(children[0]).text(); | |
const code = $(children[2]).text(); | |
if (code !== 'Postal Code') { | |
console.log(`${code}: ${stateName}`); | |
} | |
}) | |
}).catch(error => { | |
console.log(error); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment