Python俱乐部
Python
小课题
京东优惠券
http://api.thumbalizr.com/?api_key=8a123e76597abe3e7c6d25cc7a25cfbd&quality=90&width=250&encoding=png&delay=8&mode=screen&bwidth=1280&bheight=1024&url=http://www.ebay.com
根据HTTP头字段X-Thumbalizr-Status判断是否完成网页截图。
http://api.thumbalizr.com/?api_key=8a123e76597abe3e7c6d25cc7a25cfbd&quality=90&width=250&encoding=png&delay=8&mode=screen&bwidth=1280&bheight=1024&url=http://www.ebay.com GET /?api_key=8a123e76597abe3e7c6d25cc7a25cfbd&quality=90&width=250&encoding=png&delay=8&mode=screen&bwidth=1280&bheight=1024&url=http://www.ebay.com HTTP/1.1 Host: api.thumbalizr.com User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: zh-cn,zh;q=0.5 Accept-Encoding: gzip, deflate Accept-Charset: GB2312,utf-8;q=0.7,*;q=0.7 Proxy-Connection: keep-alive Cookie: __utma=237931845.1239597877.1309787148.1309787148.1309789909.2; __utmc=237931845; __utmz=237931845.1309789909.2.2.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=thumbalizr; __utmb=237931845.7.10.1309789909; amember_nr=462fe9a5bd2109c863c82683f66254d8; PHPSESSID=vm04ma1v4l99mhlp7od9g1due4m4q2g7 Cache-Control: max-age=0 HTTP/1.1 200 OK Date: Mon, 04 Jul 2011 14:55:50 GMT Server: Apache/2.2.3 (Linux/SUSE) X-Powered-By: PHP/5.2.6 Expires: Mon, 04 Jul 2011 14:56:50 GMT Cache-Control: max-age=3600, must-revalidate Pragma: no-cache X-Thumbalizr-URL: http://www.ebay.com X-Thumbalizr-Generated: Mon, 04 Jul 2011 14:55:50 GMT X-Thumbalizr-Status: QUEUED Content-Type: image/jpeg Content-Length: 5125 Proxy-Connection: Keep-Alive Connection: Keep-Alive
$thumbalizr_config= array( 'api_key' => "8a123e76597abe3e7c6d25cc7a25cfbd", //put your api key here 'service_url' => "http://api.thumbalizr.com/", // don't change, if you didn't have a special service contract 'use_local_cache' => TRUE, // TRUE or FALSE for local image cache 'local_cache_dir' => "cache", //relative cache directory must exists in install directory and rwx permissions to all (777) 'local_cache_expire'=> 12 // local chache expiration time in hours ); $thumbalizr_defaults= array( 'width' => "250", // image width 'delay' => "8", // caputre delay useful for flash content 5 - 10 is a good value 'encoding' => "png", // jpg or png 'quality' => "90", //image quality 10-90 'bwidth' => "1280", // browser width 'mode' => "screen", // screen or page 'bheight' => "1024" // browser height only for mode=screen ); function __construct() { global $thumbalizr_config,$thumbalizr_defaults; $this->api_key=$thumbalizr_config['api_key']; $this->service_url=$thumbalizr_config['service_url']; $this->use_local_cache=$thumbalizr_config['use_local_cache']; $this->local_cache_dir=$thumbalizr_config['local_cache_dir']; $this->local_cache_expire=$thumbalizr_config['local_cache_expire']; $this->encoding=$thumbalizr_defaults['encoding']; $this->quality=$thumbalizr_defaults['quality']; $this->delay=$thumbalizr_defaults['delay']; $this->bwidth=$thumbalizr_defaults['bwidth']; $this->mode=$thumbalizr_defaults['mode']; $this->bheight=$thumbalizr_defaults['bheight']; $this->width=$thumbalizr_defaults['width']; } private function build_request($url) { $this->request_url= $this->service_url."?". "api_key=".$this->api_key."&". "quality=".$this->quality."&". "width=".$this->width."&". "encoding=".$this->encoding."&". "delay=".$this->delay."&". "mode=".$this->mode."&". "bwidth=".$this->bwidth."&". "bheight=".$this->bheight."&". "url=".$url; $this->local_cache_file=md5($url)."_".$this->bwidth."_".$this->bheight."_".$this->delay."_".$this->quality."_".$this->width.".".$this->encoding; $this->local_cache_subdir=$this->local_cache_dir."/".substr(md5($url),0,2); }