Open Graph Protocol Parser for Node.js
"ogp-parser" is a node.js library to extract some information such as OGP, SEO from website.
[IMPORTANT]
From v0.5.0, we modified our library to use axios and we can extract oEmbed information. So v0.5.0 has some destructive changes.
please check my package.json
npm install -S ogp-parser
npm test
If you want to see coverage:
npm run test-cov
const ogp = require('ogp-parser');
import ogp from 'ogp-parser'
From v0.5, we have supported to extract oEmbed information. To extract oEmbed, we will use any href attribute in the link tag that has either types:
application/json+oembed
text/xml+oembed
const ogp = require("ogpParser");
console.log("URL:"+url);
ogp(url).then(function(data) {
console.log(JSON.stringify(data, null, " "));
}).catch(function(error) {
console.error(error);
});
{
"title": "うきょう(@ukyoda)さん | Twitter",
"ogp": {
"al:ios:url": [
"twitter://user?screen_name=ukyoda"
],
"al:ios:app_store_id": [
"333903271"
],
"al:ios:app_name": [
"Twitter"
],
"al:android:url": [
"twitter://user?screen_name=ukyoda"
],
"al:android:package": [
"com.twitter.android"
],
"al:android:app_name": [
"Twitter"
]
},
"seo": {
"robots": [
"NOODP"
],
"description": [
"うきょう (@ukyoda)さんの最新ツイート 独立系SIer。ビッグデータや機械学習を使ったシステム開発によく携わっています。 最近はPythonが多いですが、JavascriptとかPHPとかJavaとかC/C++での開発もやってます。 https://t.co/y8iW4rQ7lD ザクソン村"
],
"msapplication-TileImage": [
"//abs.twimg.com/favicons/win8-tile-144.png"
],
"msapplication-TileColor": [
"#00aced"
],
"swift-page-name": [
"profile"
],
"swift-page-section": [
"profile"
]
},
"oembed": {
"url": "https://twitter.com/ukyoda",
"title": "",
"html": "<a class=\"twitter-timeline\" href=\"https://twitter.com/ukyoda?ref_src=twsrc%5Etfw\">Tweets by ukyoda</a>\n<script async src=\"https://platform.twitter.com/widgets.js\" charset=\"utf-8\"></script>\n",
"width": null,
"height": null,
"type": "rich",
"cache_age": "3153600000",
"provider_name": "Twitter",
"provider_url": "https://twitter.com",
"version": "1.0"
}
}
You need to request oEmbed information besides an normal http request.
If you won't need oEmbed information in your application, you can disable to extract it by using skipOembed
option.
const parser = require("ogp-parser");
const url = "https://twitter.com/ukyoda";
parser(url, { skipOembed: true }).then(function(data) {
console.log(JSON.stringify(data, null, " "));
}).catch(function(error) {
console.error(error);
});
{
"title": "うきょう(@ukyoda)さん | Twitter",
"ogp": {
"al:ios:url": [
"twitter://user?screen_name=ukyoda"
],
"al:ios:app_store_id": [
"333903271"
],
"al:ios:app_name": [
"Twitter"
],
"al:android:url": [
"twitter://user?screen_name=ukyoda"
],
"al:android:package": [
"com.twitter.android"
],
"al:android:app_name": [
"Twitter"
]
},
"seo": {
"robots": [
"NOODP"
],
"description": [
"うきょう (@ukyoda)さんの最新ツイート 独立系SIer。ビッグデータや機械学習を使ったシステム開発によく携わっています。 最近はPythonが多いですが、JavascriptとかPHPとかJavaとかC/C++での開発もやってます。 https://t.co/y8iW4rQ7lD ザクソン村"
],
"msapplication-TileImage": [
"//abs.twimg.com/favicons/win8-tile-144.png"
],
"msapplication-TileColor": [
"#00aced"
],
"swift-page-name": [
"profile"
],
"swift-page-section": [
"profile"
]
}
}
I publish this library as MIT License.
I'm not going to place special regulations to use this library if the range of the license.
And I make no guarantees even if you got some accidents to use this library.