使用新浪财经7*24直播的数据

简单的做一个山寨品

在线地址:[痛苦啊,有GFW,却没有vpn,往heroku上传浪费了好多时间。。。]

http://wangxinsheng.herokuapp.com/sinaFinLive

效果图:

---

代码:

css:直接使用新浪的

index[代码简单,不写注释了]:

 <html>
<head>
<title>新浪财经[7*24直播]</title>
<link rel="stylesheet" href="live_fin_v1.css">
<script src='jquery-1.11.1.min.js'></script>
</head>
<body>
<style>
.bd_topic{cursor:pointer;}
</style>
<div class="wrap clearfix">
<div class="bd_weibo">
<div class="bd_tt clearfix">
<div class="bd_topics clearfix">
<span class="bd_topic bd_topic_cur" onclick='setTagAndGet(0,this);'>全部</span>
<span class="bd_topic"><a onclick='setTagAndGet(10,this);'>A股</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(1,this);'>宏观</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(2,this);'>行业</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(3,this);'>公司</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(4,this);'>数据</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(5,this);'>市场</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(6,this);'>观点</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(7,this);'>央行</a></span>
<span class="bd_topic"><a onclick='setTagAndGet(8,this);'>其他</a></span>
</div>
<div class="bd_refresh clearfix">
<div class="refresh_ck">
<label class="autorefreshlb" for="autorefresh"><span class="autorefreshsecs">X</span><span class="autorefreshlbtxt">秒后刷新</span></label>
</div>
</div>
</div>
<div class="bd_c">
<div class="bd_c0" id="bd_c0">
<!-- data list -->
</div>
</div>
</div>
</div>
<script>
/*
// 文字转16进制
var toUnicode = function (s) {
var str = "";
for (var i = 0; i < s.length; i++) {
str +="\\u"+s.charCodeAt(i).toString(16)+"\t";
}
return str;
}
var a = '胜多负89%少'; document.write(toUnicode(a)); // \u80dc \u591a \u8d1f \u5c11
// 16进制转文字
var toStr = function (n){
var str = "";
var s = n.split('\\u');
for(var i = 0;i < s.length;i++){
str += String.fromCharCode(parseInt(s[i],16))+"\t";
}
return str;
}
var b = "\\u80dc \\u591a \\u8d1f \\u5c11\\u3002\\u8fbe";
b = "\\u53d1\\u6539\\u59d4\\u6279\\u51c6\\u5efa\\u8bbe\\u9999\\u683c\\u91cc\\u62c9\\u81f3\\u4e3d\\u6c5f\\u516c\\u8def\\uff0c\\u9879\\u76ee\\u9884\\u8ba1\\u6295\\u8d44203\\u4ebf\\u5143\\u4eba\\u6c11\\u5e01\\u3002 \\u65b0\\u6d6a\\u4e8b\\u4ef6\\u76f4\\u64ad"; document.write(toStr(b)); // 胜 多 负 少
*/
// 时间戳转日期
function getDate(tm){
var tt=new Date(parseInt(tm) * 1000);//.toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
return tt;
}
// 数据取得或的callBack方法
function t14222533(data){
if(data.result.status.code==0){
if(data.result.data.length>0){
//append
for(var i = data.result.data.length-1;i >=0;i--){
var item = data.result.data[i];
var day = getDate(item.created_at);
var dayName = day.getFullYear()+"年"+((day.getMonth()+1)<10?'0'+(day.getMonth()+1):(day.getMonth()+1))+"月"+(day.getDate()<10?'0'+day.getDate():day.getDate())+"日";
var timeName = ((''+day.getHours()).length<2?('0'+day.getHours()):day.getHours())+":"+((''+day.getMinutes()).length<2?('0'+day.getMinutes()):day.getMinutes())+":"+((''+day.getSeconds()).length<2?('0'+day.getSeconds()):day.getSeconds());
var tmpStr = oneData.replace(/\{\%today\%\}/g,dayName).replace(/\{\%id\%\}/g,item.id).replace(/\{\%day\%\}/g,dayName).replace(/\{\%time\%\}/g,timeName).replace(/\{\%tag\%\}/g,'').replace(/\{\%content\%\}/g,item.content);
var display = 'none';
tmpStr = tmpStr.replace(/\{\%display\%\}/g,display);
$("#bd_c0").prepend(tmpStr); $("div[data-today='"+dayName+"']").find(".bd_date").hide();
$("div[data-today='"+dayName+"']").eq(0).find(".bd_date").show();
/* 隐藏当天日期
var toDay = new Date();
todayName=toDay.getFullYear()+"年"+((toDay.getMonth()+1)<10?'0'+(toDay.getMonth()+1):(toDay.getMonth()+1))+"月"+(toDay.getDate()<10?'0'+toDay.getDate():toDay.getDate())+"日";
$("div[data-today='"+todayName+"']").find(".bd_date").hide();
*/
id = item.id;
}
} $(".autorefreshsecs").html(maxTime);
clearTimeout(setTimeoutObj);
setTimeoutObj = setTimeout(animate,1000);
//console.log('go');
}else{
console.log(data);
}
}
/*
http://live.sina.com.cn/zt/api/f/get/finance/globalnews1/index.htm?format=json&callback=t14222547&id=114975&tag=0&pagesize=15&dire=b&dpc=1 http://live.sina.com.cn/zt/api/f/get/finance/globalnews1/index.htm?format=json&callback=t14222533&id=114986&tag=0&pagesize=45&dire=f&dpc=1 t14222533({"result":{"status":{"code":0,"msg":"\u83b7\u53d6\u6210\u529f, succ"},"pageStr":{"totalPage":1,"pageSize":45,"prePage":1,"nextPage":1,"firstPage":1,"lastPage":1,"totalNum":1,"pName":"page","page":1,"paramStr":"http:\/\/live.sina.com.cn\/zt\/api\/app_zt\/f\/get\/finance\/globalnews1\/index.htm\/?format=json&callback=t14222533&id=114986&tag=0&pagesize=45&dire=f&"},"data":[{"id":"114988","mid":"3803267903335890","sp_id":"152","uid":"3969238805","content":"\u53d1\u6539\u59d4\u6279\u51c6\u5efa\u8bbe\u9999\u683c\u91cc\u62c9\u81f3\u4e3d\u6c5f\u516c\u8def\uff0c\u9879\u76ee\u9884\u8ba1\u6295\u8d44203\u4ebf\u5143\u4eba\u6c11\u5e01\u3002","source":"<a href=\"http:\/\/app.weibo.com\/t\/feed\/6n8uPl\" rel=\"nofollow\">\u65b0\u6d6a\u4e8b\u4ef6\u76f4\u64ad<\/a>","created_at":"1422253192","original_pic":"","pic_ids":"","video":"","reposts":0,"comments":0,"attitudes":0,"pmid":"0","re_mid":"0","re_uid":"0","re_content":"","re_source":"","re_created_at":"0","re_original_pic":"","re_pic_ids":"","re_video":"","re_reposts":"0","re_comments":"0","re_attitudes":"0","is_audit":"1","is_launch":"0","is_del":"0","creator":"yongliang3","mender":"","created_time":"1422253192","modified_time":"0","notes":"","user":{"id":3969238805,"idstr":"3969238805","class":1,"screen_name":"fin_\u56fe\u6587\u76f4\u64ad","name":"fin_\u56fe\u6587\u76f4\u64ad","province":"11","city":"1000","location":"\u5317\u4eac","description":"","url":"","profile_image_url":"http:\/\/tp2.sinaimg.cn\/3969238805\/50\/5690088076\/1","profile_url":"u\/3969238805","domain":"","weihao":"","gender":"m","followers_count":1849,"friends_count":2,"pagefriends_count":0,"statuses_count":72181,"favourites_count":0,"created_at":"Wed Jan 08 15:47:33 +0800 2014","following":false,"allow_all_act_msg":false,"geo_enabled":true,"verified":false,"verified_type":-1,"remark":"","ptype":0,"allow_all_comment":true,"avatar_large":"http:\/\/tp2.sinaimg.cn\/3969238805\/180\/5690088076\/1","avatar_hd":"http:\/\/ww4.sinaimg.cn\/crop.0.0.179.179.1024\/ec95c715jw1ecc6o54vfcj2050050aad.jpg","verified_reason":"","verified_trade":"","verified_reason_url":"","verified_source":"","verified_source_url":"","follow_me":false,"online_status":0,"bi_followers_count":0,"lang":"zh-cn","star":0,"mbtype":0,"mbrank":0,"block_word":0,"block_app":0,"credit_score":80,"urank":11},"base62mid":"C1n0OdZOG","base62pmid":"","base62re_mid":"","pic_ids_plus":"","re_pic_ids_plus":"","tag":[{"tag_id":"2","tag_name":"\u884c\u4e1a"}]}]}});
*/ var oneData = '<div class="bd_list" data-today="{%today%}">'
+'<div class="bd_i bd_i_og bd_i_1st clearfix " data-id="{%id%}">'
+'<div class="bd_date" style="display:{%display%};">{%day%}<!--2015年1月1日--></div>'
+'<div class="bd_i_time clearfix">'
+'<p class="bd_i_time_c">{%time%}<!--19:32:37--></p>'
+'<p class="bd_i_tags"> {%tag%}<!--类型-->&nbsp;</p>'
+'</div>'
+'<div class="bd_i_c">'
+'<div class="bd_i_txt clearfix">'
+'<p class="bd_i_txt_c">{%content%}</p>'
+'</div>'
+'</div>'
+'</div>'; var scriptStr = "<script id=\'getData\' src=\'{%url%}\'><\/script>";
var pagesize = 10;
var tag = 0;
var urlStr = 'http://live.sina.com.cn/zt/api/f/get/finance/globalnews1/index.htm?format=json&callback=t14222533&id={%id%}&tag={%tag%}&pagesize={%pagesize%}&dire=f&dpc=1';
var id = '114765';
var orgId = '114765';
var scriptObj = null;
var maxTime = 60;
var setTimeoutObj = null;
function getData(){
$('#getData').remove();
var urlTmp = urlStr.replace(/{%id%}/g,id).replace(/{%pagesize%}/g,pagesize).replace(/{%tag%}/g,tag);
scriptObj = $((scriptStr.replace(/{%url%}/g,urlTmp)));
$('body').append(scriptObj);
//console.log(scriptObj);
}
$(function(){
var urlTmp = urlStr.replace(/{%id%}/g,id).replace(/{%pagesize%}/g,pagesize).replace(/{%tag%}/g,tag);
scriptObj = $((scriptStr.replace(/{%url%}/g,urlTmp)));
$('body').append(scriptObj);
$(".autorefreshsecs").html(maxTime);
});
function animate(){
var time = parseInt($(".autorefreshsecs").html())-1;
$(".autorefreshsecs").html(time);
//console.log(time);
if(time==0){
getData();
}else{
clearTimeout(setTimeoutObj);
setTimeoutObj = setTimeout(animate,1000);
}
};
function setTagAndGet(tag,obj){
$(".autorefreshsecs").html(maxTime);
$("#bd_c0").html('');
clearTimeout(setTimeoutObj);
$('.bd_topic_cur').removeClass('bd_topic_cur');
$(obj).addClass('bd_topic_cur');
id=orgId;
tag=tag
$('#getData').remove();
var urlTmp = urlStr.replace(/{%id%}/g,id).replace(/{%pagesize%}/g,pagesize).replace(/{%tag%}/g,tag);
scriptObj = $((scriptStr.replace(/{%url%}/g,urlTmp)));
$('body').append(scriptObj);
} </script> </body>
</html>

---

CSDN下载:

http://download.csdn.net/detail/wangxsh42/8398785

[模仿][JS]新浪财经7*24直播的更多相关文章

  1. video.js支持m3u8格式直播

    为什么要使用video.js? 1. PC端浏览器并不支持video直接播放m3u8格式的视频 2. 手机端各式各样的浏览器定制的video界面风格不统一,直接写原生的js控制视频兼容性较差 3. v ...

  2. js 弹窗广告24小时显示一次

    弹窗24小时显示一次 https://www.w3cschool.cn/javascript/js-cookies.html 我们需要借助cookie来实现这个功能 function setcooki ...

  3. python中字符串的处理总结

    在爬取新浪财经7*24直播中, 遇到了Unicode编码中文转utf-8的问题, 采用如下代码可以实现转化 >>> a='\\u76d1\\u7ba1\\u5bf929' >& ...

  4. 利用Docker挂载Nginx-rtmp(服务器直播流分发)+FFmpeg(推流)+Vue.js结合Video.js(播放器流播放)来实现实时网络直播

    原文转载自「刘悦的技术博客」https://v3u.cn/a_id_75 众所周知,在视频直播领域,有不同的商家提供各种的商业解决方案,其中比较靠谱的服务商有阿里云直播,腾讯云直播,以及又拍云和网易云 ...

  5. Swiper.js 中文API手册

    本文分享自 http://www.cnblogs.com/scavengers/p/3760449.html ---------------------------华丽的分割线------------ ...

  6. 基于nginx的rtmp直播服务器(nginx-rtmp-module实现)

    首先,在搭建服务之前先了解下目前主流的几个直播协议: 1.RTMP: 实时消息传输协议,Real Time Messaging Protocol,是 Adobe Systems 公司为 Flash 播 ...

  7. 在这个看脸的世界,该如何优雅的创建JS对象

    Javascript是一门解释型的语言,是基于对象的,严格来说并不怎么符合的面向对象的标准,显著的特点就是函数就是“一等对象”,与传统的面向对象语言不同的时,Javascript有“一千种”方法来创建 ...

  8. HTML5 audio元素如何使用js与jquery控制其事件

    前言: 每一次遇见问题想到的就是怎么解决?最好的方法还是查询网络媒体,更好的办法是让自己记忆,只有自己理解到了才真正是属于自己.要做一个订单提醒功能,没有使用audio相关的插件,虽然插件无数,还是喜 ...

  9. 当爬虫遇到js加密

    当爬虫遇到js加密 我们在做python爬虫的时候经常会遇到许多的反爬措施,js加密就是其中一种. 破解js加密的方法也有很多种: 1.直接驱动浏览器抓取数据,无视js加密. 2.找到本地加密的js代 ...

随机推荐

  1. Oracle数据库入门——常用的数据字典

    一.oracle数据字典主要由以下几种视图构成:1.user视图以user_为前缀,用来记录用户对象的信息 2.all视图以all_为前缀,用来记录用户对象的信息及被授权访问的对象信息 3.dba视图 ...

  2. win7 or win8 系统访问2003系统上的数据库很慢

    解决方式, 执行当前命令即可  netsh interface tcp set global autotuninglevel=disabled 

  3. [原]零基础学习视频解码之seek

    现在,我们要添加一些功能,当你看不能倒带的电影,是不是很烦? 那么函数av_seek_frame功能看起来是多么赏心悦目. 我们将让左,右箭头来回走在影片中通过一个小的向上和向下箭头很多,其中“三多一 ...

  4. Java框架篇---Mybatis 入门

    一.Mybatis介绍 MyBatis是一款一流的支持自定义SQL.存储过程和高级映射的持久化框架.MyBatis几乎消除了所有的JDBC代码,也基本不需要手工去设置参数和获取检索结果.MyBatis ...

  5. hbase 使用

    hbase shell命令的使用 再使用hbase 命令之前先检查一下hbase是否运行正常 hadoop@Master:/usr/hbase/bin$ jps HMaster NameNode Se ...

  6. [原创]AHA大会回顾

    AHA大会回顾 缘起 AHA之前参加了Daniel的培训,了解到AHA大会,觉得很高大上,开始有些心动.考虑到是工作时间,而且是外地,所以也就停留在心动层面了.之后与伯薇和四正吃饭,听说他们要去参加这 ...

  7. MyBatis知多少(3)

    解决存储过程固有限制的方法之一就是将SQL嵌入到更加通用的语言中去.与存储过程将业务逻辑移入数据库相反,内联SQL将SQL从数据库移入了应用程序代码.这就使得SQL语句可以直接与语言进行交互.从某种意 ...

  8. Cwinux源码解析(一)

    我在我的个人博客发表了新的文章,欢迎各位读者批评指正. Cwinux源码解析(一)

  9. Google Kubernetes设计文档之服务篇-转

    摘要:Kubernetes是Google开源的容器集群管理系统,构建于Docker之上,为容器化的应用提供资源调度.部署运行.服务发现.扩容缩容等功能. Pod是创建.调度和管理的最小部署单位,本文详 ...

  10. Git 版本管理

    应用情景1:添加文件(单个.多个.目录)到Git版本库,提交一个版本快照. 应用情景2:穿越历史回到过去,版本回退,从当前版本回退到之前提交过的某个版本上. 应用情景3:穿越历史过头了,版本回退多了, ...