所以我试着从一个网站上抓取一些数据。有一系列的名字需要抓取。发生的情况是,如果有15个名字需要抓取。其中只有5个名字被刮掉了。
当我检查原始站点时,他们也以类似的方式加载数据。在第一次加载网站时。仅显示五个名称。在重新加载时,将显示10个名称,并再次尝试显示所有15个数据。
谁能告诉我如何让我的cURL在抓取原始数据之前等待几秒钟。这样所有的内容都可以被抓取?
以下是带有curl set选项的代码的部分代码片段:
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_AUTOREFERER, true);
curl_setopt($post, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($post, CURLOPT_TIMEOUT, 2 );
$img_contents = curl_exec($post);
curl_close($post);
$html= str_get_html($img_contents);
foreach($html->find('div[id=xxxx]') as $stay2)
{
$stay4=$stay2->find('span[class=xxx]');
foreach($stay4 as $stay6)
{
echo $abc[]= strip_tags($stay6) ."<br/>";
}
}发布于 2013-04-16 16:06:55
添加睡眠($seconds)请参阅PHP sleep function
https://stackoverflow.com/questions/16031775
复制相似问题