-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
74 lines (53 loc) · 1.83 KB
/
server.js
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var express = require('express'),
app = express(),
Promise = require("bluebird"),
writeFile = Promise.promisify(require("fs").writeFile),
request = require('request'),
cheerio = require('cheerio');
app.get('/scrape', function (req, res, next) {
url = 'http://www.imdb.com/title/tt1229340/'
request(url, function (error, response, html) {
if (!error) {
var $ = cheerio.load(html)
// var title, release, rating
// var json = {title:"", release:"", rating:""}
// $('h1').filter(function () {
// var data = $(this)
// title = data.text()
// release = data.children().children('a').text()
// json.title = title
// json.release = release
// })
// $('.ratingValue').filter(function () {
// var data = $(this)
// rating = data.children().first().children().text()
// json.rating = rating
// })
}
// writeFile('output.json', JSON.stringify(json, null, 4)).then(result => {
// console.log('file successfully written')
// }).catch(error =>{
// next(error)
// })
meta_og = []
for (var i = $('head meta[property^=og]').length - 1; i >= 0; i--) {
elem = i + ''
// if ($('head meta')[elem].attribs.property) {
// first_letters = $('head meta')[elem].attribs.property.substring(0,2)
// if ($('head meta[property^=og]')) {
// ('head meta[property^=og]')[elem]
var meta_attribs = $('head meta[property^=og]')[elem].attribs
meta_og.push([meta_attribs.property, meta_attribs.content])
// console.log("property---" + meta_attribs.property + '\ncontent---' + meta_attribs.content)
// console.log($('head meta[property^=og]')[elem].attribs.content)
// }
// }
}
// console.log($('head meta').attribs)
console.log(meta_og);
res.send('check your console')
})
})
app.listen('3000')
console.log('port is 3000')
exports = module.exports = app