使用新浪财经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. 碰到一个在app内部浏览器锚点异常的问题

    最近在做一个文章评论的功能,其中一个需求是:在提交完评论后,需要跳转到位于页面底部的评论区域,正常情况下location.href=http://m.hostname.cn/article#comme ...

  2. CSS HACK 及常见问题

    一.CSS常用hack 1.方式一:条件注释法 这种方式是IE浏览器专有的Hack方式,微软官方推荐使用的hack方式.举例如下 只在IE下生效 <!--[if IE]> 这段文字只在IE ...

  3. HIVE: SerDe应用实例

    数据文件内容 id=123,name=steven id=55,name=ray 期望输出格式 123 steven 55 ray 1. 创建表, 用正则表达式的形式指定格式 create table ...

  4. 3D全景!这么牛!!

    如果你用过网页版的百度地图,你大概3D全景图浏览是一种怎样的酷炫体验:在一个点可以360度环顾周围的建筑.景色,当然也可以四周移动,就像身临其境. 全景图共分为三种: ①球面全景图 利用一张全景图围成 ...

  5. 同时支持控制台和MFC窗口程序的APP

    BOOL CMyApp::InitInstance() { if ( m_bShowGui==FALSE ) { FILE *stream = NULL; AllocConsole(); // 开辟控 ...

  6. JavaScript 属性描述符

    属性描述符(Property Descriptor)是 ES5 之后出现的概念,顾名思义,它用于描述属性应该是什么样,例如是否只读,能否枚举,能否可配置等.所有对象属性均可使用属性描述符来定义. 属性 ...

  7. ios auto layout demystified (一)

    Ambiguous Layout 在开发过程中,你可以通过调用hasAmbiguousLayout 来测试你的view约束是否足够的.这个会返回boolean值.如果有一个不同的frame就会返回ye ...

  8. Membership三步曲

    http://www.cnblogs.com/jesse2013/p/membership-part1.html http://www.cnblogs.com/jesse2013/p/membersh ...

  9. Rainyday.js – 傻眼了!竟然有如此逼真的雨滴效果

    Rainyday.js 是一个轻量的 JavaScript 库,利用 HTML5 Canvas 实现雨滴下落在玻璃表面的动画效果.Rainyday.js 尽可能的模拟现实的雨滴效果,几乎可以以假乱真了 ...

  10. SQL年月日方面的查询信息

    这是计算一个月第一天的SQL 脚本:   SELECT DATEADD(mm, DATEDIFF(mm,0,getdate()), 0) --当月的第一天 SELECT DATEADD(mm, DAT ...