没事的时候想抓取点网页看看,也不太懂,只是玩玩,写了点代码,聊以娱乐。
稍微有点意义的函数是:get_content_by_socket(), get_url(), get_content_url(), get_content_object 几个函数,也许能够给你点什么想法。
'\\s]+)[\'>]*\s*/i;
$reg = '/^(down.*?\.html)$/i';
preg_match_all ($rex, $file_contents, $r);
$result = ; //array();
foreach($r as $c){
if (is_array($c)){
foreach($c as $d){
if (preg_match($reg, $d)){ $result .= $host_url . $d.\n; }
}
}
}
return $result;
}
//获取指定内容中的多媒体文件
function get_content_object($str, $split=|--:**:--|){
$regx = /href\s*=\s*['\]*([^>'\\s]+)[\'>]*\s*(.*?)/i;
preg_match_all($regx, $str, $result);
if (count($result) == 3){
$result[2] = str_replace(多媒体: , , $result[2]);
$result[2] = str_replace(, , $result[2]);
$result = $result[1][0] . $split .$result[2][0] . \n;
}
return $result;
}
?>