2017-07-29 62 views
3

我想在本地主機上學習HTML DOM解析。但是我在開始時就崩潰了。簡單的HTML DOM解析無法正常工作

1)我做了一個新的項目

2)我從simplehtmldom.sourceforge.net

3下載的文件)我已經把這段代碼我的HTML項目

<!DOCTYPE html> 
<!-- 
To change this license header, choose License Headers in Project Properties. 
To change this template file, choose Tools | Templates 
and open the template in the editor. 
--> 
<html> 
    <head> 
     <meta charset="UTF-8"> 
     <title></title> 
    </head> 
    <body> 
     <?php 
     // put your code here 
     $html = file_get_html('http://www.google.com/'); 
     ?> 
    </body> 
</html> 

4)我進去這個錯誤,當我運行腳本時:

致命錯誤:未捕獲錯誤:調用未定義的函數file_get_html()在C:\ xampp \ htdocs \ PhpProject1 \ index.php:15 Stac k trace:在第15行拋出C:\ xampp \ htdocs \ PhpProject1 \ index.php中的#0 {main}

我在這裏誤解了什麼嗎?

+0

您需要使用DOM解析器。詳細信息[這裏](https://sourceforge.net/projects/simplehtmldom/files/) –

+0

@AshiqurRahman我已經下載了這些文件,並將它們放在我的項目文件夾中 – ragulin

+0

您需要在HTML代碼中包含DOM解析器PHP庫文件。 –

回答

0

我認爲PHP DOM解析器庫不再支持以PHP最新版本所以,你需要使用的是它會幫助你捲曲。

<?php 
$curl = curl_init(); 
curl_setopt($curl, CURLOPT_URL, "http://www.google.co.in"); 
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); 
$result = curl_exec($curl); 
curl_close($curl); 
print $result; 
?> 

試試這個..!

0

file_get_html不屬於php

要使用它,您需要下載幷包含PHP Simple HTML DOM Parser

然後你可以使用它像這樣

include_once('simple_html_dom.php'); 
$html = file_get_html('http://www.google.co.in'); 
0

您需要包括使用PHP包括功能在你的HTML代碼中的DOM解析器PHP庫文件。

<html> 
    <head>  
     <meta charset="UTF-8"> 
     <title></title> 
    </head> 
    <body> 
     <?php 
      include_once('domparser.php');// use your file location 
     // put your code here 
     $html = file_get_html('http://www.google.com/'); 
     ?> 
    </body> 
</html>