问题描述
首先,我想说,我不太确定哪里发布,但它是非常多的编程相关。如果这是错误的地方,我很抱歉,请让我知道我应该在哪里发布。当在朋友墙上分享文章时,Facebook将抓住一个缩略图的文章。他们如何总是从文章中获得正确的缩略图?
它没有抓住为例,而是抓住正确的图像元素对应于文章。
我正在寻找类似的东西,并想知道一个很好的方法来解析html来找到给出这个例子的图像。谢谢。
实际上,Facebook的缩略图查找方式并不那么神奇。它搜索一组< meta>
和< link>
标签,这些标签指定哪个标题,描述和要使用的图像。
如果找不到任何< meta>
和 < link>
标签,它基本上要求用户选择哪个< img>
标签适合。
在NY Times的情况下,它使用以下内容:
< meta name =thumbnailcontent =whatever.jpg/>
Facebook建议您使用< link>
标签代替缩略图。
< meta name =titlecontent =title/>
< meta name =descriptioncontent =description/>
< link rel =image_srchref =thumbnail_image/>
First off I want to say that I wasn't really sure where to post this but it is very much programming related. If it is in the wrong spot I apologize and please let me know where I should post it instead.
When sharing an article on a friends wall, facebook will grab a thumbnail of the article. How do they always get the right thumbnail from articles?
It doesn't grab the logo img element of of http://www.nytimes.com/2010/06/07/world/asia/07convoys.html?hp for example but rather grabs the correct image element that corresponds with the article.
I'm looking to do something similar and was wondering of a good way to parse the html to find the image given this example. Thanks.
Actually, Facebook's way of finding thumbnails isn't so magical. It searches for a set of <meta>
and <link>
tags which specify which title, description, and image to use.
If it cannot find any of the <meta>
and <link>
tags it is looking for, it basically asks the user to choose whichever <img>
tag fits.
In the case of the NY Times, it uses the following:
<meta name="thumbnail" content="whatever.jpg" />
Facebook recommends you use a <link>
tag instead for the thumbnail.
<meta name="title" content="title" />
<meta name="description" content="description " />
<link rel="image_src" href="thumbnail_image" />
这篇关于Facebook如何知道要解析的文章?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!