PHP简单HTML DOM解析器在多个类上返回null
我正在尝试使用简单的HTML DOM解析器从远程url解析此HTML:PHP简单HTML DOM解析器在多个类上返回null,php,html,html-parsing,Php,Html,Html Parsing,我正在尝试使用简单的HTML DOM解析器从远程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> 但它不起作用,我知道标记,我尝试添加if语句,但仍然不起作用,如下所示: include (
<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>
但它不起作用,我知道
标记,我尝试添加if语句,但仍然不起作用,如下所示:
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 ;
}
}
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 ;
}
}
}
但一切都没有起作用:(
有什么想法吗
我试过了,它正在起作用
是否显示或记录了任何PHP错误或警告?另外,在您的include中,getdomain
是系统中定义的符号吗?还是函数?是getdomain获取域,当我尝试获取其他元素如titleecho$html->find('title',0)时,代码工作正常->纯文本;
,但对于具有多个类的类,它失败了。首先,请考虑您命名的内容以及原因。如果getdomain是一个方法,请考虑camelCase
,我非常确定一个方法或函数总是需要()
如果所述方法/函数不需要额外的参数-如果它是一个已定义的常量,那么我会使用CAPSCASE
,这不是因为你想对其他开发人员大喊大叫,而是为了提醒他们getdomain
是一个常量。否则它看起来像一个输入错误,要么是一个开头缺少$
的变量,要么是一个有趣的变量缺少()
-最后getdomain
听起来像一个getter
那么如何设置它呢?
<?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 ;
}
}