简单的html dom - 类名称中的空格 [英] simple html dom - space in class name

查看:242
本文介绍了简单的html dom - 类名称中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用PHP Simple HTML DOM从网站的源代码(不是我的)获取元素,并且当我找到名为board List的ul类时,找不到。我认为它可能是一个空间的问题,但我不知道如何解决它。



这是一段php代码:

  $ html = str_get_html($ result ['content']); //获取站点的html 
$ board = $ html-> find('。board List'); //找到所有元素class = board List,但在我的情况下它不起作用,其他类名称可以工作

,这是该网站的一段HTML代码:

 <! -  OTHER HTML CODE在此之前 - >< ul class =board List>< li id =c111131class =skin_tbl> 
< table class =mbackcellpadding =0cellspacing =0onclick =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>论坛< / div>< div class = yy> Statistiche< / div>< div class =zz> Ultimo Messaggio< / div>< / div>
< ul class =big_list><! - 其他HTML之后 - >


解决方案


  $ board = $ html->解决了这个问题,找到(名单); 

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


I'm using PHP Simple HTML DOM to get element from a source code of a site (not mine) and when I find a ul class that is called "board List",this is not found.I think it might be a problem of space but I don't know how to solve it.

this is a piece of php code:

$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

and this is a piece of html code of the site:

<!-- 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 -->

解决方案

I solved it by removing board from the find parameter,as this:

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

now the parser seems to work correctly

这篇关于简单的html dom - 类名称中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆