【问题标题】:How to run PHP Simple HTML DOM Parser on Windows with WAMP?如何使用 WAMP 在 Windows 上运行 PHP Simple HTML DOM Parser?
【发布时间】:2014-03-05 16:45:59
【问题描述】:

我目前正在运行安装了 WAMPWindows 7

我正在尝试安装 PHP Simple HTML DOM Parser (http://simplehtmldom.sourceforge.net/) 以运行以下代码。

我收到一条致命错误消息。这可能是因为 DOM Parser 未安装或未安装在正确的位置。

如何安装解析器?我是简单地将它复制到 WAMP 文件夹中还是从 php 文件中调用它?

错误:

 Fatal error: Call to undefined function file_get_html() in     
 C:\wamp\www\PHP_SCRAPER\_jobs\jobs_dom.php on line 4

<?php 

代码:

// Create DOM from URL or file
$html = file_get_html('http://www.google.com');

// Find all images 
foreach($html->find('img') as $element) 
       echo $element->src . '<br>';

// Find all links 
foreach($html->find('a') as $element) 
       echo $element->href . '<br>';

?>     

【问题讨论】:

    标签: php parsing dom wamp


    【解决方案1】:
    <?php
    
    // Include the php dom parser    
    include_once 'path_to_php_dom_parser.php';
    
    // Create DOM from URL or file
    
    $html = file_get_html('http://www.google.com');
    
    // Find all images 
    foreach($html->find('img') as $element) 
           echo $element->src . '<br>';
    
    // Find all links 
    foreach($html->find('a') as $element) 
           echo $element->href . '<br>';
    
    ?> 
    

    您需要将解析器脚本从您存储在服务器上的位置包含进来

    【讨论】:

      猜你喜欢
      • 2017-06-08
      • 1970-01-01
      • 2019-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-12
      • 2012-04-08
      相关资源
      最近更新 更多