我正在使用此库(PHP简单HTML DOM解析器)来解析链接,这是代码:
$htmlUrl = 'http://trailers.apple.com/trailers/independent/thelook/includes/playlists/web.inc';
$html = file_get_html($htmlUrl);
当我打印时:
print_r($html . "\n");
向我输出这个(html树):
<h2>
<span class="dropdown-handle" id="trailers-handle">
<span id='single-trailer-info'>Info</span>
<span class='button'>
...
然后我想找到一个带有类的元素(下拉列表):
$divList = $html->find('.dropdown-list'); // tried find('.dropdown-list', 0);
然后我打印:
print_r($divList);
输出这个(数组):
simple_html_dom_node Object
(
[nodetype] => 1
[tag] => div
[attr] => Array
(
[class] => dropdown-list
)
[children] => Array
...
并采取永远的解析!
难道我做错了什么?一些链接具有此输出(数组)而不是输出(html树)。
谢谢你的帮助 :)
尝试在print_r之前清除或关闭(对不起,我忘记了,先尝试一个然后再尝试另一个)。
$html->clear();
$html->close();
如果那不起作用,并且您知道要“查找”的对象是某种选择器类型,则应首先获取所有这些选择器。然后搜索它们,如果可以的话,可以更快地进行搜索。因此,如果首先<select>
查找所有这些内容,则对它们进行查找,或者甚至不使用find并使用foreach
and自己解析它们strpos
。
如果那不起作用,请尝试先使用抓取您的页面wget
,然后将它们保存到服务器后再使用html简单dom对其进行解析。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句