
目前开放的资料都是穷举的方式,非常低效,本文将详解核心算法(图片还原算法,非穷举)和PHP示例代码,以及多线程全站抓取配合SQL数据库自动爬虫的技术讨论,下载部分采用curl多线程技术
2017年写的爬虫测试程序,后来又写了爬全站精华的爬虫,仅供技术研究。请遵守网站版权约定,本篇仅作技术探讨。
简述一下工作流程:
1.读取html文件,提取xml部分(批量部分读取api分页,并根据url存入数据库)
2.根据xml提取关键内容,对比宽度最大的分级,并存储相关参数
3.依照算法对最大分级图片进行下载,如L4
4.对下载的碎片进行拼接,方法有2种,通过Krp或PHP进行拼合
5.删除碎片文件,储存xml文件
部分代码如下,未涉及核心碎片还原算法及多线程下载,有意研究,请QQ联系购买完整代码(通用下载碎片类全景图)及720yun全站精华爬虫
if($qyun!=''){
$Su='';
$xmlname='';
$su_host_tmp=parse_url($qyun);//分解域名
$su_host=$su_host_tmp['host'];
$qyun_html_temp=get_720yun_html($qyun);
$xml_temp=get_720yun_xml($qyun_html_temp);
$xml_temp_fit=preg_replace('/(&[a-zA-Z]{1,10};)|(&#x[0-9]{1,10};)/','',$xml_temp[0]);//解决xml非法字符,造成simplexml无法载入
if($set_formatxml_type=='format'){
$xml_temp_fit_encode=urlencode($xml_temp_fit);
$xml_temp_format=json_decode(curl_post($xml_format_host,$xml_format_url,'xml='.$xml_temp_fit_encode));
$xml_format_file_temp=$xml_temp_format->fxml;
$xml_format_file=simplexml_load_string($xml_format_file_temp);
}
$tourxml=simplexml_load_string($xml_temp_fit);
}
else if (is_file($xmlname)|check_file_exists($xmlname)) {
if($Su==''){
if(empty(parse_url($xmlname)['scheme'])){
$su_host='default';
}else{
$su_host_tmp=parse_url($xmlname);//分解域名
$su_host=$su_host_tmp['host'];
}
}else{
$su_host_tmp=parse_url($Su);//分解域名
$su_host=$su_host_tmp['host'];
}
$xmlname_temp=file_get_contents($xmlname);
$xmlname_temp_fit=XmlSafeStr($xmlname_temp);//解决xml非法字符,造成simplexml无法载入
if($set_formatxml_type=='format'){
$xml_temp_fit_encode=urlencode($xmlname_temp_fit);
$xml_temp_format=json_decode(curl_post($xml_format_host,$xml_format_url,'xml='.$xml_temp_fit_encode));
$xml_format_file_temp=$xml_temp_format->fxml;
$xml_format_file=simplexml_load_string($xml_format_file_temp);
}
$tourxml = simplexml_load_string($xmlname_temp_fit);}
else{
echo "<script>alert('请输入有效xml文件地址!');location.href='".$_SERVER["HTTP_REFERER"]."';</script>";
}
$scenecount = count($tourxml->scene);//全景场景数
//获取各场景各关键值
for ($i = 0; $i < $scenecount; $i++) {
$levelcount = count($tourxml->scene[$i]->image->level);
for ($w = 0; $w < $levelcount; $w++) {
$levdata[$i][] = $tourxml->scene[$i]->image->level[$w]['tiledimagewidth'];
}
}
for ($i = 0; $i < $scenecount; $i++) {
$levdata_sec[$i] = max(toArray($levdata[$i]));
}
for ($i = 0; $i < $scenecount; $i++) {
$levelcount = count($tourxml->scene[$i]->image->level);
$scene_name[$i] = $tourxml->scene[$i]['name'];
$tilesize[$i]=$tourxml->scene[$i]->image['tilesize'];
for ($w = 0; $w < $levelcount; $w++) {
if($levdata_sec[$i]==toArray($tourxml->scene[$i]->image->level[$w]['tiledimagewidth'])){
$cubedata[$i][] = $tourxml->scene[$i]->image->level[$w]->cube['url']->asXML();
}
}
}
for ($i=0; $i <count($tourxml->scene); $i++) {
$cube_tmp[]=get_kr_url($cubedata[$i][0]);
$cube_full_tmp[]=get_kr_full_url($cubedata[$i][0]);
$cube_lev[]=substr($cube_tmp[$i][0], 0,2);
$cube_zero[]=substr($cube_tmp[$i][0], 4.5,1);
}
if (preg_match("/(http:\/\/)|(https:\/\/)/", $cube_full_tmp[0][0])){
$host_tmp=parse_url($cube_full_tmp[0][0]);
$host_dir=substr_replace($host_tmp['path'],'',0,1);
}else{
$host_dir=$cube_full_tmp[0][0];
}