普通网友 2015-10-20 01:01
浏览 31
已采纳

无法从其他页面获取准确的值

I am trying to get score table from this page http://www.skysports.com/football/competitions/bundesliga/table. I do this with

$bundes = file('http://www.skysports.com/football/competitions/bundesliga/table');

And when i try to display array $bundes i do it with this:

echo '<pre>', print_r($bundes), '</pre>';

The code witch i try do display is displayed like this:

[1437] => 
[1022] => German Bundesliga 2015/16
#   Team    Pl  W   D   L   F   A   GD  Pts Last 6
1   [1059] => [1060] => Bayern Munich [1061] => [1062] =>   9   9   0   0   29  4   25  27  [1072] =>
[1073] =>
[1074] =>

This is the first row of table. And now i can display $bundes[1060] and i get output of Bayer Munich but how can i get values from $bundes[1062], values are 9, 9, 0, 0, 29, 4, 25 and 27? I need to display each of this values in <td></td> When i try to echo $bundes[1062] i get nothing.

  • 写回答

1条回答 默认 最新

  • dongwang6837 2015-10-20 02:00
    关注

    A more reliable way of extracting the data is using DOM manipulation classes to do something like:

    $doc = new \DOMDocument();
    @$doc->loadHTMLFile('http://www.skysports.com/football/competitions/bundesliga/table');
    
    $xpath = new \DOMXPath($doc);
    $rows = $xpath->query('//tbody/tr');
    
    $data = [];
    
    foreach ($rows as $i => $row) {
        $columns = $xpath->query('td', $row);
    
        foreach ($columns as $column) {
            $data[$i][] = trim($column->textContent);
        }
    }
    
    print_r($data);
    

    Which gives you:

    Array
    (
        [0] => Array
            (
                [0] => 1
                [1] => Bayern Munich
                [2] => 9
                [3] => 9
                [4] => 0
                [5] => 0
                [6] => 29
                [7] => 4
                [8] => 25
                [9] => 27
                [10] => 
            )
    ...
    

    Regarding Dagon's comment, no terms can disallow crawling and extracting the data (as long as you do so at a reasonable rate that does not impact the website's performance). Terms of use & copyright law, however, do dictate what you can and cannot do with the crawled content (ex. republish).

    Web scraping may be against the terms of use of some websites. The enforceability of these terms is unclear (see "FAQ about linking – Are website terms of use binding contracts?").

    - Wikipedia, Web scraping: Legal issues

    BTW, the pages robots meta tag does allow INDEX.

    展开全部

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 根据历年月数据,用Stata预测未来六个月汇率
  • ¥15 DevEco studio开发工具 真机联调找不到手机设备
  • ¥15 请教前后端分离的问题
  • ¥100 冷钱包突然失效,急寻解决方案
  • ¥15 下载honeyd时报错 configure: error: you need to instal a more recent version of libdnet
  • ¥15 距离软磁铁一定距离的磁感应强度大小怎么求
  • ¥15 霍尔传感器hmc5883l的xyz轴输出和该点的磁感应强度大小的关系是什么
  • ¥15 vscode开发micropython,import模块出现异常
  • ¥20 Excel数据自动录入表单并提交
  • ¥30 silcavo仿真,30分钟,只需要代码
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部