PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

php文章内容抓取解决方法

原创
2016-06-13 12:04:37 717浏览

php文章内容抓取

本帖最后由 yanfangphp 于 2014-08-13 10:14:37 编辑 求大神帮忙抓取这个网页http://sports.sohu.com/zhongchao.shtml的排行榜部分的数据(包括积分榜和射手榜)



------解决方案--------------------
$url = 'http://sports.sohu.com/zhongchao.shtml';
$s = file_get_contents($url);
preg_match_all('/(?)\s
/isU', $s, $m);
print_r(preg_grep('/名次/', $m[0]));
Array
(
    [2] => 
















......接下来自己做
------解决方案--------------------
给你推荐个类  simple_html_dom


include "simple_html_dom.class.php";

$url = "http://sports.sohu.com/zhongchao.shtml";
$dom = new simple_html_dom();
$html = $dom->load(file_get_contents($url));

$res = $html->find("div#turnIDB div.turn");
# 积分榜
echo $res[0]->outertext;
# 射手榜
echo $res[1]->outertext;


结果

------解决方案--------------------
$str=file_get_contents("http://sports.sohu.com/zhongchao.shtml");

preg_match_all('/
\s*
名次球队场次积分
01广州恒大2045
02北京国安
(.+?)\s*(.+?)\s*(\d+)\s*(.+?)\s*/i',$str,$match1);

foreach($match1 as $k=>$v){
if($k!=0){
foreach($v as $k1=>$v1){
if($k1 $jifen[$k][]=$v1;
}else{
$sheshou[$k][]=$v1;
}
}
}
}
echo "
";
print_r($jifen);
print_r($sheshou);
echo "
";
/*
Array
(
    [1] => Array
        (
            [0] => 01
            [1] => 02
            [2] => 03
            [3] => 04
            [4] => 05
            [5] => 06
            [6] => 07
            [7] => 08
            [8] => 09
            [9] => 10
            [10] => 11
            [11] => 12
            [12] => 13
            [13] => 14
            [14] => 15
            [15] => 16
        )

    [2] => Array
        (
            [0] => 广州恒大
            [1] => 北京国安
            [2] => 广州富力
            [3] => 上海东亚
            [4] => 贵州茅台
            [5] => 山东鲁能
            [6] => 天津泰达
            [7] => 江苏舜天
            [8] => 上海绿地
            [9] => 长春亚泰
            [10] => 杭州绿城
            [11] => 大连阿尔滨
            [12] => 上海申鑫
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。