【问题标题】:simple_html_dom.php failed to open stream: No such file or directorysimple_html_dom.php 无法打开流:没有这样的文件或目录
【发布时间】:2015-07-29 22:14:00
【问题描述】:

我试图在 WAMP 中使用简单的 html dom 解析器 - 由于某种原因,我无法让 php 文件识别解析器 - 我正在使用解析器网站上的示例代码,但它不起作用 - 代码是如下;

 <?php
include_once('C:\wamp\www\reports\simple_html_dom.php');

function scraping_digg() {
// create HTML DOM
$html = file_get_html('http://digg.com/');

// get news block
foreach($html->find('div.news-summary') as $article) {
    // get title
    $item['title'] = trim($article->find('h3', 0)->plaintext);
    // get details
    $item['details'] = trim($article->find('p', 0)->plaintext);
    // get intro
    $item['diggs'] = trim($article->find('li a strong', 0)->plaintext);

    $ret[] = $item;
}

// clean up memory
$html->clear();
unset($html);

return $ret;
}


// -----------------------------------------------------------------------------
// test it!

// "http://digg.com" will check user_agent header...
ini_set('user_agent', 'My-Application/2.5');

$ret = scraping_digg();

foreach($ret as $v) {
echo $v['title'].'<br>';
echo '<ul>';
echo '<li>'.$v['details'].'</li>';
echo '<li>Diggs: '.$v['diggs'].'</li>';
echo '</ul>';
}

?>

到目前为止,我已经尝试过如下路径;

 include_once('C:\wamp\www\reports\simple_html_dom.php');
 include_once('http://localhost/reports/simple_html_dom.php');

include_once('simple_html_dom.php');

这是我收到的错误消息

) 警告:include_once(../../simple_html_dom.php): 无法打开流:C:\wamp\www\reports\example_scraping_digg.php 第 2 行中没有这样的文件或目录

警告:include_once():在 C:\wamp\www\reports\example_scraping_digg 中打开 '../../simple_html_dom.php' 以包含 (include_path='.;C:\php\pear') 失败。 php 在第 2 行

我还在第 6 行遇到另一个错误..;

致命错误:在第 6 行调用 C:\wamp\www\reports\example_scraping_digg.php 中未定义的函数 file_get_html()

提前感谢您提供的任何帮助 - 非常感谢。

有问题的文件位于:C:\wamp\www\reports\simple_html_dom.php 这就是为什么我很困惑 - 再次感谢您的帮助

【问题讨论】:

  • 仔细阅读错误信息并检查文件是否存在于该路径并检查文件的权限。
  • 你能分享一下你的目录结构吗?
  • 感谢您的回复-文件目录是正确的-这就是为什么我很困惑,它的位置如下.. C:\wamp\www\reports\simple_html_dom.php 我试过了仅使用根文件夹中的文件名 - 但这似乎对我也不起作用
  • this 文件在哪里,您在此处显示的那个?

标签: php wamp simple-html-dom


【解决方案1】:

查看问题数小时后 - WAMP 文件夹中的 php.ini 设置不正确 - 谢谢

【讨论】:

    猜你喜欢
    • 2017-05-04
    • 1970-01-01
    • 2013-01-13
    • 2015-11-13
    • 2011-07-04
    • 2017-06-16
    相关资源
    最近更新 更多