node.js获取前端数据
Two of this blog's most popular posts are Facebook Open Graph META Tags and How to Create a Twitter Card. I'm not at all surprised because we as content creators want some visual control over how our site is represented and shared on third party sites, especially social media sites. I was recently posting a link on Tech.pro and they instantly grab open graph information about the page, prepopulating known information, just like Facebook and Twitter, and that got me thinking about the other side of open graph data -- scraping data from a site. Look no further than the open-graph-scraper JavaScript module!
该博客中最受欢迎的两个帖子是Facebook Open Graph META标签和How to Create a Twitter Card 。 我一点都不感到惊讶,因为我们作为内容创建者希望对我们的网站在第三方网站(尤其是社交媒体网站)上的表示和共享方式进行某种视觉控制。 我最近在Tech.pro上发布了一个链接,他们立即获取有关页面的开放图形信息,并像Facebook和Twitter一样预先填充了已知信息,这让我开始思考开放图形数据的另一面-从现场。 看看open-graph-scraper JavaScript模块别无所求 !
After installing the module from NPM or GitHub, getting Open Graph information from a given URL is easy:
从NPM或GitHub 安装模块后,从给定URL获取开放图谱信息很容易:
var ogs = require('open-graph-scraper'); ogs( { url: 'https://davidwalsh.name' }, // Settings object first function(er, res) { console.log(er, res); } // Callback ); /* Result: { data: { success: 'true', ogImage: 'https://davidwalsh.name/wp-content/themes/punky/images/logo.png', ogTitle: 'David Walsh - JavaScript, HTML5 Consultant', ogUrl: 'https://davidwalsh.name/', ogSiteName: 'David Walsh Blog', ogDescription: 'David Walsh Blog features tutorials about MooTools, jQuery, Dojo, JavaScript, PHP, CSS, HTML5, MySQL, and more!' }, success: true } */Simple API and simple result -- lovely. Of course every programming language will have an equivalent library but we all know JavaScript is king! Happy sharing everyone!
简单的API和简单的结果-可爱。 当然,每种编程语言都会有一个等效的库,但是我们都知道JavaScript为王! 祝大家分享愉快!
翻译自: https://davidwalsh.name/open-graph-data-nodejs
node.js获取前端数据