【问题标题】:Parsing with class that's more than one word用不止一个词的类进行解析
【发布时间】:2013-03-19 23:01:50
【问题描述】:

我正在尝试解析这个表(只显示了一部分):

<table width="100%" cellpadding="0" cellspacing="0" id="row-item-all-0-1" class="my-day-menu-table" style="">
    <tr class="always-show-me">
        <td colspan="3"><strong>Dinner</strong></td>
    </tr>

    <tr class="price- menu-item-type-1">
        <td width="24%" class="child-odd border-candidate station" style="vertical-align:top;" rowspan="1">
            <strong>options</strong>
        </td>
        <td class="child-odd description">
            <strong>pasta express</strong> <img class="tipbox vegetarian" src="http://www.cafebonappetit.com/images/public/menu-item-type-orange.png" alt="vegetarian" />
        </td>
        ...
    </tr>
    ...
</table>

我想获取具有“child-odd border-candidate selection”类的文本“options”,但是当我使用简单的 HTML Dom 解析器时,它似乎不喜欢它,因为该类不止一个词。我该怎么做?请注意,我尝试将类名放在引号中,但没有成功。

【问题讨论】:

  • 请注意,这不是一个有多个单词的类,它是多个类的列表。
  • "child-odd border-candidate selection" 不是一个单独的类,它是四个独立的类。

标签: php html parsing html-parsing


【解决方案1】:

这个类不超过一个词,它是不同的类。您应该可以通过这种方式使用 Simple HTML DOM Parser 获取该元素:

$el = $html->find('div[class=child-odd border-candidate selection]');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-21
    • 1970-01-01
    • 1970-01-01
    • 2013-03-18
    • 2011-08-03
    相关资源
    最近更新 更多