-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
34 lines (28 loc) · 1.26 KB
/
server.js
File metadata and controls
34 lines (28 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var express = require('express');
var request = require('request');
var cheerio = require('cheerio');
var artoo = require('artoo-js');
var app = express();
app.get('/scrape', function(req, res){
var url = req.param('url');;
var repeatedNode = req.param('repeated-node');;
var params = req.param('params');
/*
url = "http://www.amazon.in/s/ref=sr_pg_6?rh=i%3Aaps%2Ck%3Acomputer+table&page=6&keywords=computer+table&ie=UTF8&qid=1459248975&spIA=B015W1X4A4,B015W1X45E,B01683PX36,B01683PK8Y,B019A5PKWS,B01683PPTS,B01D1N852W,B0198NC5DO&lo=apparel";
repeatedNode = '#s-results-list-atf a.s-access-detail-page';
params = {url: 'href', title: 'text', img: function(){return $(this).parent().parent().parent().find('img.s-access-image').attr('src')}, category: function(){return $(this).parent().parent().find('a.a-size-small>span.a-text-bold').text().slice(0, -1);}};
*/
request(url, function(err, resp, body) {
if (err)
throw err;
$ = cheerio.load(body);
// Setting artoo's context
artoo.setContext($);
//scraping goes here!
var data = artoo.scrape(repeatedNode, params);
res.send(data);
});
});
app.listen('3030')
console.log('It\'s cooking on port http://localhost:3030/scrape');
exports = module.exports = app;