<?php
$con=file_get_contents("http://it.sohu.com/7/1002/17/column203661721_3257.shtml");$preg ="#<h1>·<a href='(.*)' target='_blank'>(.*)</a><span>#iUs";preg_match_all($preg,$con,$arr);print_r($arr);/*foreach($arr[1] as $key=>$val) {
echo $val;
}*/
?>
=============================================以上采集程序,为什么采集不到内容。  还有就是,那个正则帮忙解释下。

解决方案 »

  1.   

    $con=file_get_contents("http://it.sohu.com/7/1002/17/column203661721_3257.shtml");$preg ="~<h1>·<a href='([^\"'>\s]+[^\"'>\s]+)' target='_blank'>([^<]+)</a><span>~is";preg_match_all($preg,$con,$arr);print_r($arr);
      

  2.   

    $preg ="~<h1>·<a href='([^\"'>\s]+[^\"'>\s]+)' target='_blank'>([^<]+)</a><span>([^<]+)</span></h1>~is";加上时间
      

  3.   

    我是测试过的。
    你没抓到数据是file_get_contents的问题。
    file_get_contents有时就是会得不到东西。
    你最好用fsocket或curl
      

  4.   

    是不是IP被限制了,或者cookie检测了
      

  5.   

    我都是用utf-8的,编码转化之后运行成功
    <?php
    header("Content-Type: text/html; charset=utf-8");
    $con=file_get_contents("http://it.sohu.com/7/1002/17/column203661721_3257.shtml");
    $con = mb_convert_encoding($con,'utf-8','gb2312');
    $preg ="#<h1>·<a href='(.*)' target='_blank'>(.*)</a><span>#iUs";preg_match_all($preg,$con,$arr);print_r($arr);/*foreach($arr[1] as $key=>$val) {
        echo $val;
    }*/
    ?>
      

  6.   

    那为什么需要 编码转化呢。 我建的.php文件就是utf-8的格式啊。