ste*_*rts 14
FB从HTML中删除元标记.
即,当您输入URL时,FB显示页面标题,后跟URL(截断),然后显示<meta name ="description">元素的内容.
至于缩略图的选择,我想FB可能只选择超过一定尺寸的那些,即跳过按钮图形,1px间隔物等.
编辑:我不确切地知道你在寻找什么,但这里是PHP中用于从页面中抓取相关数据的函数.
这使用来自http://simplehtmldom.sourceforge.net/的简单HTML DOM库
我已经看过FB如何做到这一点,看起来刮擦是在服务器端完成的.
class ScrapedInfo
{
public $url;
public $title;
public $description;
public $imageUrls;
}
function scrapeUrl($url)
{
$info = new ScrapedInfo();
$info->url = $url;
$html = file_get_html($info->url);
//Grab the page title
$info->title = trim($html->find('title', 0)->plaintext);
//Grab the page description
foreach($html->find('meta') as $meta)
if ($meta->name == "description")
$info->description = trim($meta->content);
//Grab the image URLs
$imgArr = array();
foreach($html->find('img') as $element)
{
$rawUrl = $element->src;
//Turn any relative Urls into absolutes
if (substr($rawUrl,0,4)!="http")
$imgArr[] = $url.$rawUrl;
else
$imgArr[] = $rawUrl;
}
$info->imageUrls = $imgArr;
return $info;
}
| 归档时间: |
|
| 查看次数: |
3682 次 |
| 最近记录: |