画面キャプチャ サービスを提供するWeb サイトhttp://ctrlq.org/screenshots/を見つけました。多くの URL からスクリーン キャプチャをバッチ リクエストしたいので、プログラムでそれを行うための PHP cURL スクリプトを作成しました。
この Web サービスからスクリーン キャプチャ イメージを取得するには、キャプチャする必要のあるセキュア コードと Web サイト URL を含む POST データが必要でした。
以下のコードは、上記の 2 つのアクションを実行する cURL スクリプトです。
$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;
残念ながら、ソースコードを入手しました:
Sorry but the tool couldn't capture that web page. Please <a href='/screenshots/'>try another URL</a>.
成功コードにはスクリーン キャプチャ イメージ リンクが含まれている必要があります。
<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>
この cURL スクリプトに誤りはありますか? ありがとう。