【发布时间】:2014-02-28 15:21:27
【问题描述】:
我需要你的帮助!自从两天没有成功以来,我一直在用头撞砖墙。 我是 PHP 新手(几个月前开始使用)。
我使用类 Simple HTML Dom Parser 从网页中获取一些信息:
1°) "library-" 后面的数字。 示例:199459
加上一系列链接:
2°) "/index.php/link-to-get-878220"
我尝试通过这种方式在标签中获取这些信息:
大批 ( [电影] => 数组 ( [199459] => /index.php/link-to-get-878219 [199459] => /index.php/link-to-get-878220 [198210] => /index.php/link-to-get-878452 [198210] => /index.php/link-to-get-878453 [198210] => /index.php/link-to-get-878454 [198210] => /index.php/link-to-get-878455 ) )如您所见,每个数字(即:198210)是多个值的键(id="library-??????" 的div中包含的所有值都具有相同的键)
问题:
- 我在尝试获取号码时遇到了一些浪费(即:movies_1)。
- 我没有成功并行数组中的数字和链接(这就是我没有在代码中添加示例的原因)
英语不是我的母语,所以请不要犹豫,就我使用的一些词提出见解!
我的代码:
include('simple_html_dom.php');$movies = array();
$html = new simple_html_dom();
$html->load_file("pt.html");
foreach($html->find('div.libraries div[id*=library-]') as $library):
$movies['idMovie'][] = str_replace('library-', '', $library->id);
foreach($html->find('.list-movies tr') as $links):
$movies['links'][] = $links->find('.nom a',0)->href;
endforeach;
endforeach;
我尝试获取信息的 HTML 来自:
<div class="libraries library_movie-tabs red tabs">
<div class="libraries library_element-tabs red tabs">
<div id="library-199459" class="tabs-content">
<div class="inner">
<p class="info"><strong>Library 1:</strong>Fantasy Movies</p>
</div>
<div class="inner">
<table width="100%" class="library-table list-movies">
<tr>
<td width="40"></td>
<td width="228" class="nom"><a title="Conan"
href= "/index.php/link-to-get-878219"></td>
</tr>
<tr>
<td width="40"></td>
<td width="228" class="nom"><a title="Lord-Of-The-Ring"
href= "/index.php/link-to-get-878220"></td>
</tr>
</table>
</div>
<div id="library-movies_1" class="library-movies">
...
</div>
</div>
<div id="library-198210" class="tabs-content">
<div class="inner">
<p class="info"><strong>Library 2 :</strong>S-F Movies</p>
</div>
<div class="inner">
<table width="100%" class="library-table list-movies">
<tr>
<td width="40"></td>
<td width="228" class="nom"><a title="Tron"
href= "/index.php/link-to-get-878452"></td>
</tr>
<tr>
<td width="40"></td>
<td width="228" class="nom"><a title="Starwars"
href= "/index.php/link-to-get-878453"></td>
</tr>
<tr>
<td width="40"></td>
<td width="228" class="nom"><a title="Star-Trek"
href= "/index.php/link-to-get-878454"></td>
</tr>
<tr>
<td width="40"></td>
<td width="228" class="nom"><a title="Predator"
href= "/index.php/link-to-get-878455"></td>
</tr>
</table>
</div>
<div id="library-movies_1" class="library-movies">
...
</div>
</div>
</div>
</div>
【问题讨论】:
标签: php simple-html-dom