【发布时间】:2017-07-12 00:06:18
【问题描述】:
尝试从网站上的模板中动态提取 HTML 元素。 {{SCHEMA - Recipe Image}} 和 {{SCHEMA - Recipe Description}} 无法正常工作。 {{SCHEMA - Recipe Image}} 引用了正确的部分,但在 Google 的结构化数据测试工具中返回 null(为 image.url 提供的值必须是有效的 URL)。{{SCHEMA - Recipe Description}},当我创建文章架构时它工作,由于某种原因不适用于这种类型的架构,并给了我一个
第 9 行,字符 5 处的错误:解析错误。 '}' 预期
错误。
谁能帮我理解为什么没有正确提取图片 URL 和描述?
<script>
(function(){
var data = {
"@context": "http://schema.org",
"@type": "Recipe",
"author": "Example",
"cookTime": "PT1H",
"description": "Generic description goes here.",
"image": {
"@type": "ImageObject",
"url": {{SCHEMA - Recipe Image}}
},
"recipeIngredient": [
{{SCHEMA - Recipe Ingredient}}
],
"name": {{SCHEMA - Recipe Title}},
"prepTime": "PT15M",
"recipeInstructions": {{SCHEMA - Recipe Steps}}
}
var script = document.createElement('script');
script.type = "application/ld+json";
script.innerHTML = JSON.stringify(data);
document.getElementsByTagName('head')[0].appendChild(script);
})(document);
</script>
【问题讨论】:
-
描述已修复,通过变量仍然无法拉取图像 URL,是我使用了错误的代码吗?
标签: json seo google-tag-manager structured-data