写两个js函数操作scrapy框架爬虫


第一个js得到jobid,然后第二个函数获取run中id,判断即可

<script src="http://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script type="text/javascript">
//地图
function city_map(city) {
var map = new BMap.Map("allmap");
var point = new BMap.Point(116.331398,39.897445);
map.centerAndZoom(city,12);
}

//判断url是否合法
function checkURL(URL){
var str=URL;
//判断URL地址的正则表达式为:http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
//下面的代码中应用了转义字符"\"输出一个字符"/"
var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
var objExp=new RegExp(Expression);
if(objExp.test(str)==true){
return true;
}else{
return false;
}
}


function requests(url){
api_url="get_city_from_domain"
$.ajax({
method:'GET',
data:{"url":url},
url:api_url,
success:function(data){
//alert(data)
city_map(data)
}
});
}

//scrapy_crawl
function scrapy_crawl(url){
api_url="http://localhost:6800/schedule.json"
$.ajax({
method:'POST',
data: {'project':'SeeMeiSpider', 'spider':'spider'},
url:api_url,
success:function(data){
//var a=JSON.stringify(data);
//alert(a);
var jobid = data.jobid;
//alert(b);
scrapy_crawl_check(url,jobid)
//alert(JSON.stringify(data));
}
});
}

function scrapy_crawl_check(url,jobid){
api_url="http://localhost:6800/listjobs.json?project=SeeMeiSpider"
//alert("aaaa");
$.ajax({
method:'GET',
//data: {'project':'SeeMeiSpider', 'spider':'spider'},
url:api_url,
success:function(data){
//var a=JSON.stringify(data);
//alert(typeof(a));
//alert(a);//split("");
run=JSON.stringify(data.running);
alert(data.running);
//alert(jobid);
alert(run);
alert(run.indexOf(jobid));
if(run.indexOf(jobid)==1){
//alert(jobid);
}
else{
//alert("no");
setTimeout(scrapy_crawl_check(url,jobid),1000*60*4);
}
//alert(data)
//alert(JSON.stringify(data));
}
});
}

//过度函数
function temp_hanshu(data){
alert(data);
}
//触发漏洞检测函数
$(function() {
$("#singal_url").click(function() {
add_res=""
$("#t_body").html("")
var url=$("#url_name").val();
if(checkURL(url)){
//requests(url)
scrapy_crawl(url);
//scrapy_crawl_check(url);
}
else {
alert("输入合法url")
}
});
});
</script>

2019.4.20

标签:

发表评论

电子邮件地址不会被公开。 必填项已用*标注