我正在使用简单的HTML DOM解析器来刮擦网站...如何在循环中跳过特定的类

有帮助吗?

解决方案

判断从 http://simplehtmldom.sourceforge.net/manual.htm#frag_find_attr 您可以使用:

->find("div[class!=skip_me]")

或使用DOM方法并与 ->getAttribute("class") 违反价值。

其他提示

  // DOM can load HTML soup. But, HTML soup can throw warnings, suppress
  // them.
  $htmlDom = new DOMDocument();
  @$htmlDom->loadHTML($html);
  if ($htmlDom) {
    // It's much easier to work with simplexml than DOM, luckily enough
    // we can just simply import our DOM tree.
    $elements = simplexml_import_dom($htmlDom);

这是Drupal 7最简单的报价(几乎)。之后,文档的工作要容易得多,可以将类作为$ element ['class']到达。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top