zoukankan      html  css  js  c++  java
  • php抓取网页信息

    index.php
    
    
    
    <?php
    include_once 'simple_html_dom.php';
    //获取html数据转化为对象
    $html = file_get_html('http://paopaotv.com/tv-type-id-5-pg-1.html');
    //A-Z的字母列表每条数据是在id=letter-focus 的div内class= letter-focus-item的dl标签内,用find方法查找即为 
    $listData=$html->find("#letter-focus .letter-focus-item");//$listData为数组对象
    
    foreach($listData as$key=>$eachRowData){
      $filmName=$eachRowData->find("dd span",0)->plaintext;//获取影视名称
    
      $filmUrl=$eachRowData->find("dd a",0)->href;//获取dd标签下影视对应的地址
    
      //获取影视的详细信息
      $filmInfo=file_get_html("http://paopaotv.com".$filmUrl);
      $filmDetail=$filmInfo->find(".info dl");
      foreach($filmDetail as $film){
        $info=$film->find("dd");
        $row=null;
        foreach($info as $childInfo){
          $row[]=$childInfo->plaintext;
        }
        $cate[$key][]=join(",",$row);//将影视的信息存放到数组中
      }
    }
    ?>
    
    <table border="1px solid red" width="100%">
      <tr>
        <th>主演</th>
        <th>状态</th>
        <th>类型</th>
        <th>地区</th>
        <th>标签</th>
        <th>导演</th>
        <th>时间</th>
        <th>年份</th>
      </tr>
    
    
    <?php foreach ($cate as $val){
    echo "<tr>";
      for ($i=0; $i < count($val)-1; $i++) { 
    
        echo "<td>".$val[$i]."</td>";
      }    
    echo "</tr>";
    } ?>
    
    </table>
    
    <?php 
    echo "<pre>";
    print_r($cate);
    echo "</pre>";
    
    ?>

    相关代码下载:files.cnblogs.com/files/qhorse/getspider.rar

     

  • 相关阅读:
    P3373 【模板】线段树 2
    P3372 【模板】线段树 1
    P3368 【模板】树状数组 2
    P3374 【模板】树状数组 1
    P1004 方格取数
    P1880 [NOI1995]石子合并
    UOJ#152盘子序列
    P1886 滑动窗口
    P1440 求m区间内的最小值
    二进制中1的个数
  • 原文地址:https://www.cnblogs.com/qhorse/p/5101638.html
Copyright © 2011-2022 走看看