高难度的东西来了……………………
http://www.sqsc.gov.cn/col/col19/index.html采不到网址规则 尴尬啊。。{:4_196:} 有人能找到它的 网址规则 吗? http://www.sqsc.gov.cn/col/col19/index.html
采不到网址规则 尴尬啊。。
九九 发表于 2011-2-14 16:48 http://bbs.locoy.com/images/common/back.gif
属于POST采集,好好研究下~ 你好。可以采集的呀。ali66ls 本帖最后由 zhouchanglin 于 2011-2-19 12:44 编辑
这个网站是jq的,翻页是Ajax请求的
在源码里可以发现这个js脚本函数,它是控制数据请求的关键:
$('#325').jpage
({themeName:'default',showMode:'full',totalRecord:2508,openCookies:false,dataBefore:'<table
width="99%" align="center"border="0" cellpadding="0" cellspacing="0" style="margin-
top:8px">',dataStore:InitData325,dataAfter:'</table>',groupSize:1,proxyUrl:'/module/jslib/jq
uery/jpage/dataproxy.jsp',perPage:15,barPosition:'bottom',ajaxParam:
{col:1,appid:'1',webid:1,path:'/',columnid:19,unitid:'325',webname:'宿城区政府外网门户网
站'}});把网页全部保存找到jquery.jpage js文件http://www.sqsc.gov.cn/module/jslib/jquery/jpage/jquery.jpage.js,可以找到这个函数,由于整个js文件都是这个函数,所以不贴出来了
以输入页数,并回车翻页为例,触发了下面的函数页码输入框监听,下面这个函数当用户输入页码,并按回车时会翻页,Ajax请求
valCurrentPage.keydown(
function(event){
var targetPage = parseInt($(this).val());
if(event.keyCode==13 && targetPage>=1 &&
targetPage<=totalPage){
if(!dataStore || gpStartPage > targetPage ||
(gpEndPage > 0 && gpEndPage < targetPage)){
currentPage = targetPage;
getGroupStartEnd();
getStartEnd();
getRemoteData();//解决问题的关键的
ajax请求的函数
}else{
currentPage = targetPage;
getStartEnd();
loadData();
refresh();
}
}
}
);只把其中的关键的Ajax请求的函数贴出function getRemoteData(){
startLoad();//正在检索状态
$.ajax(//ajax请求
{
type: "POST",
url: proxyUrl + "?
startrecord="+gpStartRecord+"&endrecord="+gpEndRecord+"&perpage="+perPage ,//请求地址
cache: false,
data: ajaxParam,//参数
dataType: "script",//数据类型
timeout: 30000,
success: function(msg){//成功请求执行
eval(msg);
getStartEnd();
loadData();//刷新数据容器,加载返回
数据
refresh();//刷新工具栏状态
overLoad();//结束检索状态
},
error: function(){
alert("请求失败或超时,请稍后再
试!");
overLoad();
return;
}
}
);
}
下拉框改变,点击上下页,输入页码,最后都要执行这个函数,发生Ajax请求
值得一提的是url: proxyUrl + "?
startrecord="+gpStartRecord+"&endrecord="+gpEndRecord+"&perpage="+,//请求地址,这里有gpStartRecord和gpEndRecordperPage3个变量,分别代表数据开始位置,数据结束位置,每页数量,而前两个变量是由getGroupStartEnd()函数设置的,getGroupStartEnd()函数根据每页数量,当前页等信息,设置这2个变量,路默认是每页15条,那么第1页gpStartRecord=1pEndRecord=15;第2页gpStartRecord=16pEndRecord=30,就是间隔14的规律
这样把post地址http://www.sqsc.gov.cn/module/jslib/jquery/jpage/dataproxy.jsp?startrecord=1&endrecord=15&perpage=15
连同post参数ajaxParam:col=1&appid=1&webid=1&path=/&columnid=19&unitid=325&webname=宿城区政府外网门户网站连接起来
就是Ajax的外部数据的地址了http://www.sqsc.gov.cn/module/jslib/jquery/jpage/dataproxy.jsp?startrecord=1&endrecord=15&perpage=15&col=1&appid=1&webid=1&path=/&columnid=19&unitid=325&webname=宿城区政府外网门户网站其中?后的参数的意思:
startrecord------数据开始位置
endrecord------数据结束位置
perpage-----每页数量
下面的是谷歌翻译的,大概就是这个意思吧
appid----------应用程序ID,
webid----------网站id
path-----路径
columnid------------列ID
unitid--------------单元ID
webname-----------网站名称路过每页40条数据,那么第一页地址http://www.sqsc.gov.cn/module/jslib/jquery/jpage/dataproxy.jsp?startrecord=1&endrecord=40&perpage=40&col=1&appid=1&webid=1&path=/&columnid=19&unitid=325&webname=宿城区政府外网门户网站第2页http://www.sqsc.gov.cn/module/jslib/jquery/jpage/dataproxy.jsp?startrecord=41&endrecord=80&perpage=40&col=1&appid=1&webid=1&path=/&columnid=19&unitid=325&webname=宿城区政府外网门户网站发现了吧startrecord ,endrecord ,perpage,3个参数要做些修改就行了
下面是那个js文件里的代码,我加了些其他注释,不能上传txt文件,所以用的压缩包
规则缺点是这个网站的分页地址火车头好像不能批量添加,因为地址有2个分页变量,可能借助其他的工具生成这样的地址会更方便
做采集规则发布模块,联系972130397
页:
[1]