質問

私はシンプルな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 Simpletestからの引用です。この後、ドキュメントでははるかに簡単に動作します。クラスは$ element ['class']として到達できます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top