0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

phpqueryで子要素を取得する

Posted at

  <?php
    require_once("./phpQuery-onefile.php");
    $html = file_get_contents("https://ja.wikipedia.org/wiki/%E3%82%A6%E3%82%A7%E3%83%96%E3%82%B9%E3%82%AF%E3%83%AC%E3%82%A4%E3%83%94%E3%83%B3%E3%82%B0");

    #ここでhtml全文を取得している
    $phpobj = phpQuery::newDocument($html);

    #子要素の取得
    #欲しい子要素の情報が深くにあっても
    #順番に指定すれば取得可能
    $children = $phpobj[".asbox, .plainlinks, .noprint > .mbox-image > .mbox-text"];

    echo "children";

    foreach ($children as $child) {
      echo pq($child)->text()."<br>";
      echo "----------------<br>";
    }
  ?>
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?