我不知道我在这里做错了什么。我试图使用JSOUP和Coldfusion获取og:image url。
<cfhttp method="get" url="http://www.bbc.com/culture/story/20150304-is-house-of-cards-worth-watching" result="theresult">
<cfscript>
// Create the jsoup object
Jsoup = createObject("java", "org.jsoup.Jsoup");
// HTML string
html = "#theresult.filecontent#";
// Parse the string
document = Jsoup.parse(html);
// Extract content
title = document.title();
metaOgImage = document.select("meta[property=og:image]").first();
writeOutput("
<div>Title: #title#</div>
<div>Meta: #metaOgImage#</div>
");
</cfscript>
metaOgImage = document.select("meta[property=og:image]").first();
返回一个表示<meta>
标记的元素。要仅显示"content"属性(该页面存储网址的位置),请尝试:
<div>Meta: #metaOgImage.attr("content")#</div>
请记住,如果未找到metaOgImage
,则可能为 null,因此请务必在 CF 代码中添加处理。