【问题标题】:PHP Simple HTML DOM Parser [fatal error Call to a member function find() on a non-object ]PHP 简单 HTML DOM 解析器 [在非对象上调用成员函数 find() 的致命错误]
【发布时间】:2014-11-02 23:57:54
【问题描述】:

有人知道我为什么会出现这个错误吗?我做错了什么?

<?
include('simple_html_dom.php');

$html = ("http://99designs.pt/logo-design/contests?show=finished");
foreach($html->find('span[class=active.sl_notranslate]') as $aholder) {

echo $aholder . '<br>';
}
?>

致命错误:在非对象上调用成员函数 find() ../simplehtml.php 第 5 行

【问题讨论】:

  • 在这种情况下,$html 是一个字符串,因此它不会附加任何方法。
  • 谢谢,错过了这个:$html = file_get_html($url);你知道我如何回应“span”内容吗?

标签: php html dom get


【解决方案1】:

你忘了添加函数名file_get_html,代码应该是这样的:

<?php
  include 'simple_html_dom.php';

  $html = file_get_html("http://99designs.pt/logo-design/contests?show=finished");
  foreach($html->find('span[class=active.sl_notranslate]') as $aholder) {

    echo $aholder . '<br>';
  }

?>

【讨论】:

  • 要回显跨度内容,您应该将此代码放在 foreach echo $aholder-&gt;innertext . '&lt;br&gt;'; 中查看此处的文档:simplehtmldom.sourceforge.net,它已得到很好的解释。
  • 我添加了,但什么也没返回... span 的内容来自网站的数据库。那是问题吗?在控制台上我有这个错误:“GET js.bizographics.com/insight.min.js net::ERR_BLOCKED_BY_CLIENT”
  • 不,控制台没有任何内容。我检查了您提供的网址的来源,但没有 .sl_notranslate 类的跨度。
  • 你是对的。它不是“active.sl_notranslate”。它是“活跃的 sl_notranslate”。我明白了,谢谢:)
猜你喜欢
  • 1970-01-01
  • 2017-04-30
  • 1970-01-01
  • 1970-01-01
  • 2016-10-20
  • 1970-01-01
  • 2016-02-12
  • 2016-02-09
  • 1970-01-01
相关资源
最近更新 更多