基于框架的抓取博客园首页简易资讯聚合的代码
效果图:
实现代码:复制代码代码如下:DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN ' ' http://www .w3。L1-过渡时期。DTD ' html xmlns=' http://www .w3。org/1999/XHTML ' head meta http-equiv=' Content-Type ' Content=' text/html;charset=utf-8'/title无标题文档/title/head body table id=' TBL 1 '单元格填充=' 1 '单元格间距=' 1 ' bgcolor=' # 333333 ' width=' 800 px ' style='行高:30 px'tr bgcolor=' # FFFFFF ' TD align='中心'宽度=' 70% '标题/tdtd align='center' width='30% '时间/TD/tr/table div id=' loading ' style=' display : none ' font color=' red '正在加载数据/font/div /body /html脚本语言=' JavaScript ' type=' text/JavaScript ' src=' http :https://Ajax。谷歌api。com/Ajax/libs/jquery/1。4 .2/jquery。量滴js /脚本脚本语言=' JavaScript ' type=' text/JavaScript ' $(function(){ var html=' ';var bgcolor=$。Ajax({ URL : ' http://www。cn博客。com/RSS ',type:'get ',//dataType:($.browser.msie)?text' : 'xml ',success :函数(数据){ $(' item ',data).每个(函数(索引,元素){ bgcolor=索引%2==0?bgcolor=' # f1 f1 f1 ' ' : ' bgcolor=' # FFFFFF ';html=' tr ' bgcolor ' TDA href=' ' $(this).查找('链接')。text() ''' FormatContent($(this).查找('标题')。text(),40) '/tdtd '新日期($(这个).查找(' pubDate ').text()).格式(' yyyy-MM-DD hh :MM :s ');/TD/tr ';});$('#tbl1 tr:not(':first ')').移除();//移除非第一行$('#tbl1 ').追加(html);//绑定数据到表},完成:函数(){ $(“# loading”)).hide();},在send :函数(x){//x . setrequest header(' Content-Type ',' charset=utf-8 ')之前;$("#正在加载")。show();},错误: function(){ alert(' error ');} });});/script脚本语言='javascript' /** *时间对象的格式化;*/日期。原型。format=函数(format){/* * eg : format=' YYYY-MM-DD hh :MM 3360s ';*/var o={ ' M ' :这个。getmonth()1,//month 'd ' :this.getDate(),//day 'h ' :this.getHours(),//hour 'm ' :this.getMinutes(),//minute ' S ' : this。getseconds(),//second ' q ' :数学。(这个。getmonth(3)/3)、//quarty ' S ' S ' 3:这个。得到毫秒()//毫秒测试(格式)){ format=format。替换(RegExp .$1,(this.getFullYear()' ').substr(4 - RegExp .$ 1 .长度));} for(var k in o){ if(new RegExp('(' k ')').测试(格式)){ format=format。替换(RegExp .一美元,RegExp .$1.length==1?o[k] : ('00' o[k]).substr((' o[k]).长度));} }返回格式;} //格式化标题信息函数FormatContent(单词,长度){ return word.lengthlength?word.substring(0,长度)".":字;}/脚本
版权声明:基于框架的抓取博客园首页简易资讯聚合的代码是由宝哥软件园云端程序自动收集整理而来。如果本文侵犯了你的权益,请联系本站底部QQ或者邮箱删除。