刚学PHP的那会,看过一个程序,就是可以抓取站内链接的程序。当时因为各种原因,没去细看,昨晚一时兴起,就自己写了这么一个抓链接的程序。使用说明:
1、网站的链接是绝对路径非相对路径;
2、只抓取除js css外的链接,而且只用了普通的过滤方法,有待改进;
3、将获取到的urls保存在/path/to/yourfile;
4、考虑到这个脚本需要执行很长时间,建议在命令行下执行该脚本。
$value)
{
if(stripos($value,'http://www.example.com')===false)
{
unset($matches[$key]);
}
if(stripos($value,'.ico')!==false)
{
unset($matches[$key]);
}
if(stripos($value,'.js')!==false)
{
unset($matches[$key]);
}
if(stripos($value,'.css')!==false)
{
unset($matches[$key]);
}
}
$matches = array_unique($matches);
return $matches;
}
$urllines = '';
do{
foreach(geturls($urls[$i]) as $key=>$value)
{
if(array_search($value, $urls) === false)
{
$urls[] = $value;
echo "get url: ".$value." now total: ".sizeof($urls)."\n";
$urllines .= $value;
$urllines .= "\n";
}
}
$i ++;
}
while($i < sizeof($urls));
file_put_contents('/path/to/yourfile',$urllines);
?>