2016-05-14 23 views
0

我有一个解析html页面的脚本。一个部分分析各种tr元素。假设我们有一个TR结构是这样的:phpQuery:如何解析tr的类和样式子句

<tr class="a test" style="display: none;"> 
    <td class="numeric"></td> 
    <td class="date">1/1/16</td> 
    <td class="numeric">$2.65</td> 
    .... etc.... 
</tr> 
<tr class="another tr"> 
    ...... etc...... 

这是工作的罚款当前的代码是这样的:

$the_row_I_want = $parseSectionofCodeImlookingat->find("tr:eq($rowIwant)"); 
$entire_tr_in_html = $the_row_I_want->__toString(); 

这样做是返回HTML整个TR,从中我可以解析出类名和样式部分。不过,我一直在试图找出如何使用phpQuery语法为我解析类名和样式部分。有没有办法使用phpQuery(以及如何)做到这一点?

回答

0

OK,想通了:

$the_row_I_want = $parseSectionofCodeImlookingat->find("tr:eq($rowIwant)"); 
$entire_tr_in_html = $the_row_I_want->__toString(); 
$the_class_attribute = $the_row_I_want->attr('class'); 
$the_style_attribute = $the_row_I_want->attr('style');