Picking up hidden data with the noscript tag with file_get_contents

1

I would like to retrieve information from a CAPTCHA on one form and display it on another using file_get_contents .

It happens that the page where the data is has the tag <noscript> that warns:

  

"Please enable Javascript in your browser so that the service   of captcha works correctly. "

This prevents data from being retrieved with file_get_contents .

Is there any function or other way to retrieve this data by emulating javascript enabled?

The site is this:

  

link

    
asked by anonymous 31.07.2017 / 17:32

1 answer

2

There's no way to "emulate a javascript enabled" except that you use some Webdriver, but you do not need to emulate.

Quickly reviewing the source code captcha is generated in / sabiweb / captcha-load / , it contains the value of the captcha (its ID) and also the path of the image and audio, but you can also get only the headers, it will have JSESSIONID which is the same value.

So, you're making the request the wrong way and I think this is not even necessary, but anyway.

This would be enough to get such a code, ignoring security issues:

if($captchaJS = file_get_contents('https://www2.dataprev.gov.br/sabiweb/captcha-load/')){

    preg_match('/([0-9A-Za-z\.\-_]{90,})/', $captchaJS, $achados);

    $Codigo = $achados['0'];
    $Cookie = substr($Codigo, strpos($Codigo, '_', 3) + 1);

}

So just use:

https://www2.dataprev.gov.br/sabiweb/api/imagem?d= . $Codigo

To load the image. To send the form, use the value of $Codigo and cookies of $Cookie .

But I do not think you even need it.

    
31.07.2017 / 18:33