How to delay data extraction using Curl php

0

Good evening friends today I was raised a question I'm using Curl to extract some data from a website in this way.

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$url = 'https://ycapi.org/iframe/?v=6YzGOq42zLk';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER,0); //visualizar ñ y acentos.
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_CAINFO, 'cacert.pem');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
curl_setopt($ch, CURLOPT_ENCODING, "gzip,deflate"); //(aceptación de codificación gzip)   
$response = curl_exec($ch); //almacena el response de la pagina.

curl_close($ch);

if (preg_match('#rel="nofollow" href=[^"]*"([^"]*)"#', $response, $datos)) {
    $mp = $datos[1];
} else {
    $mp = 'error';
}
echo $mp;

The code is good The problem is that the page where I extract the data have to wait a while to process the information and curl does not wait for that time and extracts the null data.

The question is, is there a way to make curl wait for the information to be available to extract the page.

I thought to use

  

sleed ();

But I really do not know where to locate, thank you in advance.

    
asked by BotXtrem Solutions 19.01.2018 в 02:34
source

1 answer

1

From what I see, the site from which you are trying to obtain the data makes use of Ajax and cURL / PHP does not process JavaScript. It is not that the data is slow to appear, it is that these requests are not being executed and however much you expect, they will not be executed.

You can try link

Greetings,

    
answered by 19.01.2018 в 12:19