简体   繁体   中英

How to run PHP Simple HTML DOM Parser on Windows with WAMP?

I am currently running Windows 7 with WAMP installed.

I am trying to install the PHP Simple HTML DOM Parser ( http://simplehtmldom.sourceforge.net/ ) to run the below code.

I am getting a fatal error message. This is likely because the DOM Parser is not installed or in the right place.

How do I install the Parser? Do I simply copy it into a WAMP folder or do I call it from a php file?

Error:

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

<?php 

Code:

// 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

// 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>';

?> 

You need to include the parser script from the location you stored it in on the server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM