根据微信号来抓取微信文章

<script type="text/javascript">
//计算字符串长度
String.prototype.strLen = function() {
    var len = 0;
    for (var i = 0; i < this.length; i++) {
        if (this.charCodeAt(i) > 255 || this.charCodeAt(i) < 0) len += 2; else len ++;
    }
    return len;
}
//将字符串拆成字符,并存到数组中
String.prototype.strToChars = function(){
    var chars = new Array();
    for (var i = 0; i < this.length; i++){
        chars[i] = [this.substr(i, 1), this.isCHS(i)];
    }
    String.prototype.charsArray = chars;
    return chars;
}
//判断某个字符是否是汉字
String.prototype.isCHS = function(i){
    if (this.charCodeAt(i) > 255 || this.charCodeAt(i) < 0) 
        return true;
    else
        return false;
}
//截取字符串(从start字节到end字节)
String.prototype.subCHString = function(start, end){
    var len = 0;
    var str = "";
    this.strToChars();
    for (var i = 0; i < this.length; i++) {
        if(this.charsArray[i][1])
            len += 2;
        else
            len++;
        if (end < len)
            return str;
        else if (start < len)
            str += this.charsArray[i][0];
    }
    return str;
}
//截取字符串(从start字节截取length个字节)
String.prototype.subCHStr = function(start, length){
    return this.subCHString(start, start + length);
}

    function parseXML(text,field){
        try{
            xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
            xmlDoc.async="false";
            xmlDoc.loadXML(text);
        }catch(e){
          try{
              parser=new DOMParser();
              xmlDoc=parser.parseFromString(text,"text/xml");
          }catch(e){
              alert(e.message);
              return;
          }
        }
        return xmlDoc.getElementsByTagName(field)[0].childNodes[0].nodeValue;
    }
        var sogou = {
            weixin:{
                gzhcb:function(object){
                    var o = object.items;
                    var htmlString = ‘‘;
                    for(var i=0;i<o.length;i++){
                        if(i>3){
                            break;
                        }
                        var str = o[i].toString();
                        var title = parseXML(str,‘title‘).toString();
                        if(title.strLen()>10){
                            title = title.subCHStr(0,30)+‘.....‘;
                        }
                        var object = {
                            title: title,
                            url: parseXML(str,‘url‘),
                            date: parseXML(str,‘date‘)
                        };
                        htmlString += ‘<li><a target="_blank" href="‘+object.url+‘"><span class="bg_dian"></span>‘+object.title+‘<span class="right_news_time">[‘+object.date+‘]</span></a></li>‘;
                    }
                    
                    $(‘#right_new_list_ul‘).append(htmlString);
                }
            }
        }
        $(function(){
            // 这个url是到微信搜狗里面针对自己的微信号找的地址
            var url = ‘http://weixin.sogou.com/gzhjs?cb=sogou.weixin.gzhcb&openid=oIWsFt7SddzriXihcBz_1yXHyfms&eqs=a5sooxSgnMwqoznexrP3Zux5mz5NrKcGnwDYMXmLTxYvm9XfC0cp8zbmU3atg%2FnPIHNq1&ekv=7&page=1&t=1436950692098&callback=?‘;
            //var url = ‘http://weixin.sogou.com/gzhjs?cb=sogou.weixin.gzhcb&openid=oIWsFt2IaC1wvHZc3EnDf4iToUcI&eqs=VfsoolZg%2B5ALoIsKSWSRru8JhJEgw1uSWON13NHPGfuO3qpheRdZMoIHzE2KxcUUP9Fym&ekv=7&page=1&t=1436882190413&callback=?‘;
            $.getJSON(url,function(data){
                data
            });
        });
        
    </script>

 

根据微信号来抓取微信文章

原文:http://www.cnblogs.com/shaoshao/p/4680637.html

为您推荐

发表评论

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