油猴抽取联行号

这段脚本展示了如何使用 Greasemonkey 用户脚本进行网页元素遍历,提取表格数据,并通过 AJAX 发送 POST 请求到指定 URL 进行进一步处理。在接收到响应后,脚本将数据插入到数据库中,确保数据的更新和同步。
摘要由CSDN通过智能技术生成
// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description     http://www.555555555cm.cn/bank/shanghai/   访问此地址其实只有一个⑤  
// @author       You
// @match        http://*/*
// @grant        GM_xmlhttpRequest
// @grant        GM_download
// @require  https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js
/* globals jQuery, $, waitForKeyElements */

// ==/UserScript==


(function() {

var str="";
    $('.table tr').each(function(i){
        if($(this).children('td').eq(0).text()!="" && $(this).children('td').eq(1).text()!=""){
        str+=  $(this).children('td').eq(0).text()+"-"+$(this).children('td').eq(1).text()+","  ;
        }
    });

   // console.log(str);

    //调用↓

    var shengfen=$('.well .bg-primary a').eq(0).text();
     var shi=$('.well .bg-primary a').eq(1).text();


    runAsync("http://d.xxxx.com/index/index/getcodes", "POST", "shengfen="+shengfen+"&shi="+shi+"&codes='"+str+"'").then((result) => {
        return result;
    }).then(function(result) {
        console.log(  result);
    });

//send数据函数
//参数1:url;参数2:请求类型get或post;参数3:post的body;
    function runAsync(url,send_type,data_ry) {

    var p = new Promise((resolve, reject)=> {


GM_xmlhttpRequest({
  method: send_type,
  url: url,
  headers: {
        "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
   },
  data:data_ry,
  onload: function(response){
      //console.log("请求成功");
      //console.log(response.responseText);

      resolve(response.responseText);

  },
   onerror: function(response){
    //console.log("请求失败");
       reject("请求失败");
  }
});

    })


    return p;

}


})();
   public function getcodes(){
         
         $ds=explode(",",$this->request->post('codes'));
         
         
         foreach ($ds as$k=>$v){
             $parms['shengfen']=$this->request->post('shengfen');
             $parms['shi']=$this->request->post('shi');
         $tem=explode("-",$v);
         $parms['code']=$tem[0];
         $parms['name']=$tem[1];
         
           
           $find= db("codes") ->where($parms)->find();
           if(!$find &&  $parms['code'] &&  $parms['name']){
            db("codes") ->data($parms)->insert();   
           }else{
              // echo json_encode($parms)."already exists or isnull____________\n";
           }
          
         
         }
         
         echo 1;
       
         
         
        // echo json_encode($parms);
     }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值