1

I found a website http://ctrlq.org/screenshots/ that providing screen capture service. I would like to batch request the screen capture from many URL, so I have written a PHP cURL script to do that programmatically.

In order to get the screen capture image from this web service, it required the POST data with a secure code and an website URL that needed to be captured.

The code below is the cURL script that doing the above two action

$url = 'http://ctrlq.org/screenshots/';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($ch);
preg_match('/<input type="hidden" name="labnol" value="(.*)" \/>/', $content, $match);
$postData = array(
    'labnol' => $match[1],
    'url' => 'http://www.google.com'
);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieFile);
curl_exec($ch);
$content2 = curl_exec($ch);
curl_close($ch);

echo $content2;

Unfortunately, I got the sources code:

Sorry but the tool couldn't capture that web page. Please <a href='/screenshots/'>try another URL</a>.

While the success code should be containing the screen capture image link:

<div class="animate" id="progressmeter">
                          <div class="progress progress-striped active">
                            <div class="bar" style="width: 0%;"></div>
                          </div>
                        </div>
                        <script>
                            var progress = setInterval(function() {
                            var $bar = $('.bar');
                            if ($bar.width()==300) {
                                clearInterval(progress);
                                $('.progress').removeClass('active');
                                document.getElementById('progressmeter').innerHTML = "<a class='btn btn-success btn-large' href='http://ctrlq.org/files/screenshots/0e82990496751f51e3329094b26bd4a1.png' target='_blank'><i class='icon-download icon-white'></i> Download Image</a>  <a class='btn-large btn btn-info' href='/screenshots/'><i class='icon-camera icon-white'></i> New Capture</a>";
                            } else {
                                $bar.width($bar.width()+30);
                            }
                            $bar.text($bar.width()/3 + 10 +  "%");
                            }, 1500);
                        </script>

I would like to ask is there any mistakes on this cURL script? Thanks.

1 Answer 1

1

You forgot to handle the session cookies. Use

curl_setopt($ch, CURLOPT_COOKIESESSION, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookiefile");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookiefile");

at the very beginning.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.