【发布时间】:2021-06-09 06:07:44
【问题描述】:
我正在尝试从 Autodesk 商店网页 (example) 上的 Microformat JSON-LD 数据中提取评级。目的是使用 badgen.net 制作评级徽章。但是,我无法让任何解析器提取 JSON-LD 数据。
我在 Runkit 上使用 node.js 来提取和解析元数据。 https://runkit.com/thomasa88/60c049de4daa38001add07ca
我尝试过使用 microformat-node 和 microformats-parser,但它们似乎都没有在页面上找到 JSON-LD 数据。如何正确提取数据?
在下面的 sn-p 中,我提取了相关的 HTML 并尝试将其提供给 microformats-parser:
response = {}
response.body = `<html><body> <script type="application/ld+json">
{
"@context": "http://schema.org/",
"@type": "SoftwareApplication",
"name": "ParametricText",
"image": "https://autodesk-exchange-apps-v-1-5-staging.s3.amazonaws.com/data/content/files/images/JLH9M8296BET/2114937992453312456/resized_930d9014-acf1-4a47-809b-a2373cf161f0_.png?AWSAccessKeyId=AKIAJGORQX2SECMU24IQ&Expires=1623357670&response-content-disposition=inline&response-content-type=image%2Fpng&Signature=T0SHZ2bodYMOIIgZDgc%2BWdWW2mU%3D",
"operatingSystem": "Win64",
"applicationCategory": "http://schema.org/DesktopApplication",
"aggregateRating":{
"@type": "AggregateRating",
"ratingValue": "5",
"ratingCount": "4"
},
"offers":{
"@type": "Offer",
"price": "0",
"priceCurrency": "USD"
}
}
</script></body></html>`
const { mf2 } = require("microformats-parser");
const parsed = mf2(response.body, {
baseUrl: "https://apps.autodesk.com"
});
console.log(parsed);
结果:
{"rels":{},"rel-urls":{},"items":[]}
【问题讨论】:
标签: node.js json-ld microformats runkit.com