替换获取标题的包
This commit is contained in:
parent
2348e22d0a
commit
30e03b4894
|
|
@ -7,17 +7,14 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"body-parser": "~1.15.1",
|
||||
"cheerio": "^0.22.0",
|
||||
"cookie-parser": "~1.4.3",
|
||||
"crypto": "0.0.3",
|
||||
"debug": "~2.2.0",
|
||||
"ejs": "~2.4.1",
|
||||
"express": "~4.13.4",
|
||||
"express-session": "^1.14.1",
|
||||
"iconv-lite": "^0.4.13",
|
||||
"morgan": "~1.7.0",
|
||||
"mysql": "^2.11.1",
|
||||
"request": "^2.78.0",
|
||||
"serve-favicon": "~2.3.0",
|
||||
"supervisor": "^0.11.0"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,7 @@
|
|||
var api = require('express').Router();
|
||||
var mysql = require('mysql');
|
||||
var crypto = require('crypto');
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
var cheerio = require('cheerio');
|
||||
var request = require('request');
|
||||
var iconv = require('iconv-lite');
|
||||
var read = require('node-readability');
|
||||
var db = require('../database/db.js');
|
||||
|
||||
api.post('/logout', function(req, res) {
|
||||
|
|
@ -333,41 +329,13 @@ api.post('/addTags', function(req, res) {
|
|||
api.post('/getTitle', function(req, response) {
|
||||
var params = req.body.params;
|
||||
var url = params.url;
|
||||
|
||||
var options = {
|
||||
url: url,
|
||||
encoding: null,
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.65 Safari/537.36'
|
||||
}
|
||||
}
|
||||
request(options, function(err, res, body) {
|
||||
var title = '';
|
||||
if (!err && response.statusCode == 200) {
|
||||
var charset = "utf-8";
|
||||
var arr = body.toString().match(/<meta([^>]*?)>/g);
|
||||
if (arr) {
|
||||
arr.forEach(function(val) {
|
||||
var match = val.match(/charset\s*=\s*(.+)\"/);
|
||||
if (match && match[1]) {
|
||||
if (match[1].substr(0, 1) == '"') match[1] = match[1].substr(1);
|
||||
charset = match[1].trim();
|
||||
return false;
|
||||
}
|
||||
})
|
||||
}
|
||||
var html = iconv.decode(body, charset);
|
||||
var $ = cheerio.load(html, {
|
||||
decodeEntities: false
|
||||
});
|
||||
title = $("title").text();
|
||||
}
|
||||
|
||||
console.log(title);
|
||||
read(url, function(err, article, meta) {
|
||||
console.log(article.title);
|
||||
response.json({
|
||||
title: title || '',
|
||||
title: article.title || '',
|
||||
});
|
||||
article.close();
|
||||
});
|
||||
})
|
||||
})
|
||||
|
||||
function md5(str) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue