2012-01-13 76 views
2

我剛剛嘗試使用簡單HTML DOM框架進行抓取:http://simplehtmldom.sourceforge.net/,但出於安全原因,服務器配置中禁用了file_get_contents是否有(PHP)Web Scraping框架使用Curl而不是file_get_contents?

我現在需要找到一個類似的使用Curl的框架 - 任何人都知道什麼?

錯誤消息試圖運行點例如斜線時,我得到的是:

Warning: file_get_contents() [function.file-get-contents]: URL file-access is disabled in the server configuration in /var/www/vhosts/domain.com/httpdocs/crawlfeed/simple_html_dom.php on line 70

+0

[如何解析和處理HTML與PHP?](http://stackoverflow.com/questions/3577641/how-to-parse-and-process-html-with-php) – mario 2012-01-13 16:02:15

+0

不能你只是cURL文件,然後將文本字符串加載到SimpleHTMLDOM中? – prodigitalson 2012-01-13 16:02:27

+0

你不必在simplehtml中使用file_get_contents。您可以使用curl自己獲取html,並直接將結果提供給simplehtml。 – 2012-01-13 16:02:33

回答

5

只要把頁面打倒捲曲,然後將字符串加載到SimpleHTMLDOM:

$ch = curl_init('http://theurl.com'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$htmlStr = curl_exec($ch); 
curl_close($ch); 

$html = new simple_html_dom(); 

// Load HTML from a string 
$html->load($htmlStr); 
+0

謝謝,對不起,作爲n00b使用簡單的HTML Dom ... – martincarlin87 2012-01-13 16:29:50

+2

這就是沒有任何藉口。從來沒有用過它......我KID,我KID ;-) – prodigitalson 2012-01-14 02:44:17

4

如果你有PHP 5.3(你應該,因爲PHP 5.2不支持了)我完全以你推薦Goutte

這是一種新的,它只是一個.phar包括在您的項目。 HTTP部分由Http Zend和套接字處理。你有強大的BrowserKit和DomCrawler Symfony組件來幫助你從HTML中提取信息(無正則表達式,無xpath)。

相關問題