Skip to content

Instantly share code, notes, and snippets.

@ryancoughlin
Last active March 6, 2018 17:33
Show Gist options
  • Save ryancoughlin/2ad1b1d475136f200a8734e7f89eb1ea to your computer and use it in GitHub Desktop.
Save ryancoughlin/2ad1b1d475136f200a8734e7f89eb1ea to your computer and use it in GitHub Desktop.
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