0

我正在尝试使用 Simple HTML DOM Parser 从远程 url 解析这个 HTML:

<div class="_5pbx userContent _3ds9 _3576" data-ft="data-ft='{"tn":"K"}'">
<p>text to be parsed</p>
<p>the rest of text</p>
</div>

我使用的 PHP 狙击如下:

include (getdomain . "/lib/simple_html_dom.php");

$html = new simple_html_dom();
$get = file_get_contents("http://localhost/get/d.json");
$html->load($get);
foreach ($html->find('div[class=_5pbx userContent _3ds9 _3576]') as $link) {
 if(isset($link)){
          echo $link->plaintext ;
    }
  }

但它没有用,我知道<p>标签,我尝试为此添加 if 语句,但仍然没有用,如下所示:

include (getdomain . "/lib/simple_html_dom.php");

$html = new simple_html_dom();
$get = file_get_contents("http://localhost/get/d.html");
$html->load($get);
foreach ($html->find('div[class=_5pbx userContent _3ds9 _3576]') as $link) {
 if(isset($link)){
foreach($link->find('p') as $tag)
    {
          echo $tag->plaintext ;
    }
  }
}

但一切都没有奏效:(

任何想法?

4

1 回答 1

0

我试过这个。这是工作..

<?php
include (getcwd() . "/simple_html_dom.php");
$html = new simple_html_dom();
$get = file_get_contents("http://localhost/zdemo/php%20selenium/d.json");
$html->load($get);
foreach ($html->find('div[class=_5pbx userContent _3ds9 _3576]') as $link) 
{
    if(isset($link))
    {
          echo $link->plaintext ;
    }
}
于 2018-07-23T06:49:31.353 回答