建站学 - 轻松建站从此开始!

建站学-个人建站指南,网页制作,网站设计,网站制作教程

当前位置: 建站学 > 网站开发 > PHP教程 >

PHP 简易爬虫

时间:2011-12-29 13:28来源: 作者: 点击:
function get_urls($url)   {   $url_array=array();   $the_first_content=file_get_contents($url);   $the_second_content=file_get_contents($url);   $pattern1 = "/http://[a-zA-Z0-9.?/-=&:+-_'"]+/";   $pattern

function get_urls($url)

  {

  $url_array=array();

  $the_first_content=file_get_contents($url);

  $the_second_content=file_get_contents($url);

  $pattern1 = "/http:\/\/[a-zA-Z0-9\.\?\/\-\=\&\:\+\-\_\'\"]+/";

  $pattern2="/http:\/\/[a-zA-Z0-9\.]+/";

  preg_match_all($pattern2, $the_second_content, $matches2);

  preg_match_all($pattern1, $the_first_content, $matches1);

  $new_array1=array_unique($matches1[0]);

  $new_array2=array_unique($matches2[0]);

  $final_array=array_merge($new_array1,$new_array2);

  $final_array=array_unique($final_array);

  for($i=0;$i

  {

  echo $final_array[$i]."
";

  }

  }

  get_urls("http://www.baidu.com");

(责任编辑:admin)
织梦二维码生成器
顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:点击我更换图片