首页 > Web开发 > 详细

php抓取网页信息

时间:2016-01-05 12:14:06      阅读:154      评论:0      收藏:0      [点我收藏+]
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

 

php抓取网页信息

原文:http://www.cnblogs.com/qhorse/p/5101638.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!