3

所以我试图从网站上抓取一些数据。有必须删除的名称列表。发生的情况是,如果有 15 个名称需要被删除。其中只有 5 个名字被刮掉。

当我检查原始站点时,他们也以类似的方式加载数据。第一次加载网站。仅显示五个名称。重新加载时显示 10 个名称并再次尝试显示所有 15 个数据。

谁能告诉我如何让我的 cURL 在抓取原始数据之前等待几秒钟。这样所有的内容都可以被刮掉?

这是带有 curl 设置选项的部分代码片段:

    $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/>";
    }
 }
4

1 回答 1

3

添加一个 sleep($seconds) 见PHP sleep 函数

于 2013-04-16T08:06:54.530 回答