2

我想从其他网站获取 div 元素。

我有我的个人资料,我尝试使用此代码。

require_once('../simple_html_dom.php');

$html=file_get_html('http://www.example.com');
$ret=$html->find("div[id=frame-gallery]");
$ret=array_shift($ret);
echo($ret);

但是这段代码给出了错误

警告:require_once(../simple_html_dom.php) [function.require-once]:无法打开流:E:\wamp\www\in.com\components\com_content\view.php 中没有这样的文件或目录在线22

致命错误:require_once() [function.require]:在 E:\wamp\www\in.com\ 中打开所需的 '../simple_html_dom.php' (include_path='.;./includes;./pear') 失败第 22 行的 components\com_content\view.php

我坚持这个请帮助我从网站获取特定 div 元素的代码片段

4

3 回答 3

4

该文件simple_html_dom.php不是您告诉 PHP 查找它的位置。

require_once('../simple_html_dom.php');

为了安全起见,请尝试使用完整路径而不是相对路径。

require_once('E:\wamp\www\in.com\components\simple_html_dom.php');

顺便说一句,如果上面的完整路径不正确,那是你的问题。这是 PHP 正在尝试的路径。

澄清一下:我只是建议 OP 切换到绝对路径来识别和确认问题的根源。使用绝对路径进行生产很少是一个好主意。

于 2010-07-11T16:41:22.107 回答
1

在 PHP 中 require 和 include 路径可能很棘手。尽可能使用完整路径。您会发现 $_SERVER['DOCUMENT_ROOT'] 对此很有用。

于 2010-07-11T17:13:59.503 回答
0

您的 inlude_path 应包含“.”,表示当前目录。

但是,如果您在通过相对名称包含文件时遇到问题,那么只需尝试使用绝对名称,例如 require_once('E:\wamp\www\in.com\components\simple_html_dom.php');

但更好的是:

require_once 'E:/wamp/www/in.com/components/simple_html_dom.php';

于 2010-07-11T17:23:13.450 回答