Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 简单html dom-类名中的空格_Php_Html_Simple Html Dom - Fatal编程技术网

Php 简单html dom-类名中的空格

Php 简单html dom-类名中的空格,php,html,simple-html-dom,Php,Html,Simple Html Dom,我正在使用PHP Simple HTML DOM从一个站点(不是我的)的源代码中获取元素,当我发现一个名为“board List”的ul类时,它没有找到。我认为这可能是一个空间问题,但我不知道如何解决它 这是一段php代码: $html = str_get_html($result['content']); //get the html of the site $board = $html->find('.board List'); // Find all element which

我正在使用PHP Simple HTML DOM从一个站点(不是我的)的源代码中获取元素,当我发现一个名为“board List”的ul类时,它没有找到。我认为这可能是一个空间问题,但我不知道如何解决它

这是一段php代码:

$html = str_get_html($result['content']); //get the html of the site
$board = $html->find('.board List');  //  Find all element which class=board List,but in my case it doesn't work,with other class name it works
这是该网站的一段html代码:

<!-- OTHER HTML CODE BEFORE THIS --><ul class="board List"><li id="c111131" class="skin_tbl">
<table class="mback" cellpadding="0" cellspacing="0" onclick="toggleCat('c111131')"><tr>
<td class="mback_left"><div class="plus"></div><td class="mback_center"><h2 class="mtitle">presentiamoci</h2><td class="mback_right"><span id="img_c111131"></span></table>
<div class="mainbg">
<div class="title top"><div class="aa"></div><div class="bb">Forum</div><div class="yy">Statistiche</div><div class="zz">Ultimo Messaggio</div></div>
<ul class="big_list"><!-- OTHER HTML AFTER THIS -->
  • 前变态 信息统计论坛

我通过从find参数中删除board来解决这个问题,如下所示:

$board = $html->find('.List');

现在解析器似乎工作正常了

我通过从find参数中删除board来解决它,如下所示:

$board = $html->find('.List');

现在解析器似乎工作正常了,答案是:不能在类名中使用空格。空间是类的分隔符

如果您有
,那么您可以使用
.container
.wrapper something
.anothersomething
作为选择器,并始终匹配该div

因此,在您的代码中有
,因此要在css选择器中获得匹配(
$html->find(“{这里是
),您可以使用eather
.board
.List
作为选择器

因此,您的行
$board=$html->find('.board List')应该更像这样:

$board = $html->find('.board.List');
// maches every element who has class 'board' AND 'List'
// Here it is really important that there is no spaces between those 2 selectors

// or

$board = $html->find('.List');
// maches every element who has class 'List'

// or

$board = $html->find('.board');
// maches every element who has class 'board'

答案是:不能在类名中使用空格。空间是类的分隔符

如果您有
,那么您可以使用
.container
.wrapper something
.anothersomething
作为选择器,并始终匹配该div

因此,在您的代码中有
,因此要在css选择器中获得匹配(
$html->find(“{这里是
),您可以使用eather
.board
.List
作为选择器

因此,您的行
$board=$html->find('.board List')应该更像这样:

$board = $html->find('.board.List');
// maches every element who has class 'board' AND 'List'
// Here it is really important that there is no spaces between those 2 selectors

// or

$board = $html->find('.List');
// maches every element who has class 'List'

// or

$board = $html->find('.board');
// maches every element who has class 'board'

对于simple,您可能希望使用:

$html->find('*[class="board List"]', 0);
$html->find('.board.List', 0);
如果您确实想使用:

$html->find('*[class="board List"]', 0);
$html->find('.board.List', 0);

然后。

使用simple,您可能会想使用:

$html->find('*[class="board List"]', 0);
$html->find('.board.List', 0);
如果您确实想使用:

$html->find('*[class="board List"]', 0);
$html->find('.board.List', 0);
那么

使用此语法,SimpleHTMLDOM将查找具有多个类属性的元素


使用此语法,SimpleHTMLDOM查找具有多个类属性的元素

类名没有空格。实际上,
ul
有两个独立的类别(
board
List
)。我不熟悉您正在使用的解析器,但我假设您的第二行应该是
$board=$html->find('.board.List')@Sadiq您的评论是正确的,您应该将其作为答案发布。解析器使用类似于CSS选择器的语法。@Sadiq:我按你说的做了尝试,但仍然没有work@Roran在这种情况下,我建议阅读解析器的文档,找到选择包含这两个类的元素的正确语法。不幸的是,我不能提供太多帮助,因为我不熟悉前面提到的解析器。类名没有空格。实际上,
ul
有两个独立的类别(
board
List
)。我不熟悉您正在使用的解析器,但我假设您的第二行应该是
$board=$html->find('.board.List')@Sadiq您的评论是正确的,您应该将其作为答案发布。解析器使用类似于CSS选择器的语法。@Sadiq:我按你说的做了尝试,但仍然没有work@Roran在这种情况下,我建议阅读解析器的文档,找到选择包含这两个类的元素的正确语法。不幸的是,我不能提供太多的帮助,因为我不熟悉前面提到的解析器。您尝试过这个吗?Simple不允许你这样选择。你试过这个吗?Simple不允许您这样选择。请详细说明您的答案。请详细说明您的答案。