因为我自己的校内页面是readable by everyone的 所以不需要登录验证就能抓取状态
因为校内的开发人员经常修改页面的版式 因此比较稳妥的办法是在状态中添加特征字符串
例如 “终于能把校内状态同步到主页上了|www.mrcongwang.com” 就是用www.mrcongwang.com来当特征字符串
抓取代码如下:
<?php
$id = $_GET['id'];
$url = ‘http://xiaonei.com/profile.do?id=’.$id;
try{
$subject = file_get_contents($url);
}catch(Exception $e){
die(”<p>unable to connect to xiaonei.com</p>”);
}
//echo $subject;
$pattern = ‘/<p>([^ ]*)www.mrcongwang.com<\/p>/’;
preg_match($pattern, $subject, $matches);
//print_r($matches);
echo $matches[0];
?>
<?php
$id = $_GET['id'];
$url = ‘http://xiaonei.com/profile.do?id=’.$id;
try{
$subject = file_get_contents($url);
}catch(Exception $e){
die(”<p>unable to connect to xiaonei.com</p>”);
}
$pattern = ‘/<p>([^ ]*)www.mrcongwang.com<\/p>/’;
preg_match($pattern, $subject, $matches);
echo $matches[0];
?>
然后再通过一小段js利用ajax把状态写到页面上
0 Responses
Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.