我怎样才能让卷发在刮刮之前等待几秒钟? [英] how can i make my curl wait for few seconds before scraping?

查看:57
本文介绍了我怎样才能让卷发在刮刮之前等待几秒钟?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我正在尝试从网站上抓取一些数据。
有必须删除的名称列表。
发生的事情是,如果有15个名称需要删除。在这5个名字中,只有5个是被删除的。

So I am trying to scrape some data from a site. There are list of names that has to be scraped. What happens is that, if there are 15 names that needs to be scraped. Out of that only 5 names are scraped.

当我检查原始站点时,它们也以类似的方式加载数据。首次加载网站时。仅显示五个名称。重新加载时会显示10个名称,然后重试会显示所有15个数据。

When I checked the original site, they too load the data in similar way. On loading the site for first time. Only five names are displayed. On reloading 10 names are displayed and trying again shows all 15 data.

有人可以告诉我如何让我的cURL等待几秒钟再抓取原始数据。

Can anybody tell me how to make my cURL wait for few seconds before scraping the original data. so that all of the content can be scraped?

这是带有curl set选项的代码片段:

Here is the part snippet of the code with curl set options:

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


推荐答案

添加处于睡眠状态($ seconds),请参见 PHP睡眠功能

Add in a sleep($seconds) See PHP sleep function

这篇关于我怎样才能让卷发在刮刮之前等待几秒钟?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆