php har解压程序

<?php
if($argc!=2){
	echo "usage: php har_extractor.php <archive file name>";
	exit();
}

$urlBase="http://a.b.com/";
$archiveFileName=$argv[1];
$data=file_get_contents($archiveFileName);
$archive=json_decode($data);
$entries=$archive->log->entries;
for($i=0;$i<count($entries);$i++){
	$entry=$entries[$i];
	$filePath=str_replace($urlBase,'',$entry->request->url);
	if(strlen($filePath)==strpos($filePath,'/')+1) $filePath.="index.html";
	$fileDir=dirname($filePath);
	$fileName=basename($filePath);
	if(strpos($fileName,'?')!==false) $fileName=substr($fileName,0,strpos($fileName,'?'));
	if($fileName=='') $fileName='index.html';
	if(!file_exists($fileDir)) mkdir($fileDir,0777,true);
	$encoding=$entry->response->content->encoding;
	
	$data=$entry->response->content->text;
	if($encoding=='base64'){
		$data=base64_decode($data);
	}
	file_put_contents($fileDir.'/'.$fileName,$data);
}

Leave a comment

Your email address will not be published. Required fields are marked *