Last active
March 6, 2018 17:33
-
-
Save ryancoughlin/2ad1b1d475136f200a8734e7f89eb1ea 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
import fs from 'fs' | |
import cheerio from 'cheerio' | |
import fetch from 'node-fetch' | |
import _ from 'lodash' | |
const scrapeRoute = { | |
method: 'GET', | |
path: '/api/scrape', | |
handler: function(request, h) { | |
const url = | |
'https://tidesandcurrents.noaa.gov/tide_predictions.html?gid=1403' | |
fetch(url) | |
.then(res => { | |
if (res.ok) { | |
const html = res.text() | |
var $ = cheerio.load(html) | |
const stations = $('table.table tr').map(function() { | |
const row = $(this) | |
const name = row.find('td.stationname a').text() | |
const stationId = row.find('td.stationid').text() | |
console.log('Name: ', name) | |
return 'foo' | |
// return { | |
// stationId, | |
// name | |
// } | |
}) | |
return 'foo' | |
} else { | |
console.error('Bad response') | |
} | |
}) | |
.catch(error => { | |
return error | |
console.error(error) | |
}) | |
} | |
} | |
export default scrapeRoute |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment