我正在尝试使用 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 ;
}
}
}
但一切都没有奏效:(
任何想法?