使用simple_html_dom.php从不同的url抓取大量数据


Scraping much data from different URLs with simple_html_dom.php

我基本上想做的事情就像这样:简单的Html DOM缓存

我得到了一切工作到目前为止,但现在我得到以下错误,因为我刮了许多网站(目前6个,我想要多达25个网站):

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 39 bytes)

i'm a PHP newbie =/…那么,我怎样才能一步一步地"序列化"内存不放弃的抓取过程呢?: -)

代码示例:

// Include the library
include('simple_html_dom.php');
// retrieve and find contents
$html0 = file_get_html('http://www.site.com/');
foreach($html0->find('#id') as $aktuelle_spiele);
file_put_contents("cache/cache0.html",$aktuelle_spiele);

事先非常感谢您的帮助!

在php.ini中,更改这一行:

memory_limit = 32M

和这个:

memory_limit = 256M//或更大的值

或者在每个使用simple_html_dom:

的php脚本的开头添加这段代码
ini_set('memory_limit', '128M'); //or a greater value

您可以在脚本开始时运行内存增加。

像这样:

ini_set('memory_limit', '128M');