Created
July 28, 2017 02:32
-
-
Save mrxf/beb888b4043389402ee38f48d85699b2 to your computer and use it in GitHub Desktop.
使用article parser提取网页内容
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ArticleParser = require('article-parser'); | |
var he = require('he'); | |
var url = 'http://mp.weixin.qq.com/s/JJbZkcBoSMW0zPzmepUr1A'; | |
ArticleParser.configure({ | |
htmlRules:{ | |
allowedTags: [ 'pre', 'p', 'img' ], | |
allowedAttributes: { | |
pre: ['style'], | |
p: ['style'], | |
img: ['src','data-src'] | |
} | |
} | |
}) | |
ArticleParser.extract(url).then((article) => { | |
article.content = he.decode(article.content); | |
article.description = he.decode(article.description); | |
return article; | |
}) | |
.then(article => console.log(article)) | |
.catch((err) => { | |
console.log(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment