diff --git a/app.js b/app.js index 58bea2d12a..0f461ac0f8 100755 --- a/app.js +++ b/app.js @@ -64,7 +64,7 @@ app.get('/api', api.getApi); app.get('/api/foursquare', passportConf.ensureAuthenticated, api.getFoursquare); app.get('/api/tumblr', passportConf.ensureAuthenticated, api.getTumblr); app.get('/api/facebook', passportConf.ensureAuthenticated, api.getFacebook); -app.get('/api/scraping', passportConf.ensureAuthenticated, api.getScraping); +app.get('/api/scraping', api.getScraping); app.get('/contact', contact.getContact); app.post('/contact', contact.postContact); diff --git a/controllers/api.js b/controllers/api.js index 75ac6c670b..16357e8943 100644 --- a/controllers/api.js +++ b/controllers/api.js @@ -2,6 +2,7 @@ var config = require('../config/config'); var User = require('../models/User'); var async = require('async'); var cheerio = require('cheerio'); +var request = require('request'); var _ = require('underscore'); var geoip = require('geoip-lite'); var FB = require('fb'); @@ -105,8 +106,16 @@ exports.getFacebook = function(req, res) { }; exports.getScraping = function(req, res) { - res.render('api/scraping', { - title: 'Web Scraping', - user: req.user + request.get('https://news.ycombinator.com/', function(error, request, body) { + var $ = cheerio.load(body); + var links = []; + $('.title').find('a').slice(0,30).each(function(i, elem) { + links.push($(elem)); + }); + res.render('api/scraping', { + title: 'Web Scraping', + links: links, + user: req.user + }); }); }; \ No newline at end of file diff --git a/public/css/ios7.less b/public/css/ios7.less index 5fccf63563..51b4e7b1cc 100644 --- a/public/css/ios7.less +++ b/public/css/ios7.less @@ -540,6 +540,10 @@ label-info { margin-bottom: 0; } +span { + vertical-align: middle; +} + // Datatables ================================================================ // Search field diff --git a/public/img/hacker_news.png b/public/img/hacker_news.png new file mode 100644 index 0000000000..45802e1dd6 Binary files /dev/null and b/public/img/hacker_news.png differ diff --git a/views/api/scraping.jade b/views/api/scraping.jade index 78663a044c..f12bb1b2b9 100644 --- a/views/api/scraping.jade +++ b/views/api/scraping.jade @@ -12,3 +12,18 @@ block content a.btn.btn-lg.btn-primary(href='https://developer.foursquare.com/docs/explore', target='_blank') i.fa.fa-film | Cheerio Screencast + + h3 + img(src='/img/hacker_news.png', width=50, height=50) + span Hacker News Frontpage + + table.table.table-condensed + thead + tr + th № + th Title + tbody + each link, index in links + tr + td= index + 1 + td!= link \ No newline at end of file