php抓取网页信息php

/ / 2019-08-13   阅读:2514
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>";
?>

完整代码下载:点击下载

我要评论

昵称:
验证码:

最新评论

共0条 共0页 10条/页 首页 上一页 下一页 尾页
意见反馈