方法不对。
定时刷新利用的是浏览器端JS访问服务器API拉取数据,然后数据在本地通过JS绘图。
楼主找到此API后,用wget/curl/.NET的webclient拉取,才是正道。
定时刷新利用的是浏览器端JS访问服务器API拉取数据,然后数据在本地通过JS绘图。
楼主找到此API后,用wget/curl/.NET的webclient拉取,才是正道。
<code class="lang-html">{"total":27,"rows":[{"time":"2016-03-13 20:00:00","aqi":"196","pm2_5":"147","pm10":"217","co":"1.501","no2":"77.000","o3":"35.000","so2":"30.000","rank":"351"},{"time":"2016-03-13 21:00:00","aqi":"185","pm2_5":"139","pm10":"206","co":"1.297","no2":"66.000","o3":"36.000","so2":"27.000","rank":"349"},{"time":"2016-03-13 22:00:00","aqi":"169","pm2_5":"128","pm10":"186","co":"1.137","no2":"58.000","o3":"38.000","so2":"22.000","rank":"347"},{"time":"2016-03-13 23:00:00","aqi":"170","pm2_5":"129","pm10":"185","co":"1.078","no2":"60.000","o3":"34.000","so2":"22.000","rank":"349"},{"time":"2016-03-14 00:00:00","aqi":"155","pm2_5":"118","pm10":"172","co":"0.999","no2":"54.000","o3":"40.000","so2":"20.000","rank":"337"},{"time":"2016-03-14 01:00:00","aqi":"122","pm2_5":"92","pm10":"133","co":"0.861","no2":"42.000","o3":"51.000","so2":"17.000","rank":"301"},{"time":"2016-03-14 02:00:00","aqi":"83","pm2_5":"61","pm10":"88","co":"0.784","no2":"28.000","o3":"73.000","so2":"13.000","rank":"217"},{"time":"2016-03-14 03:00:00","aqi":"72","pm2_5":"52","pm10":"74","co":"0.799","no2":"30.000","o3":"68.000","so2":"13.000","rank":"182"},{"time":"2016-03-14 04:00:00","aqi":"59","pm2_5":"42","pm10":"62","co":"0.796","no2":"31.000","o3":"63.000","so2":"13.000","rank":"136"},{"time":"2016-03-14 05:00:00","aqi":"58","pm2_5":"41","pm10":"61","co":"0.835","no2":"34.000","o3":"55.000","so2":"14.000","rank":"124"},{"time":"2016-03-14 06:00:00","aqi":"62","pm2_5":"44","pm10":"67","co":"0.831","no2":"35.000","o3":"51.000","so2":"14.000","rank":"142"},{"time":"2016-03-14 07:00:00","aqi":"69","pm2_5":"50","pm10":"79","co":"0.861","no2":"45.000","o3":"41.000","so2":"15.000","rank":"156"},{"time":"2016-03-14 08:00:00","aqi":"79","pm2_5":"58","pm10":"93","co":"0.892","no2":"49.000","o3":"46.000","so2":"20.000","rank":"176"},{"time":"2016-03-14 09:00:00","aqi":"87","pm2_5":"64","pm10":"98","co":"0.882","no2":"39.000","o3":"72.000","so2":"22.000","rank":"190"},{"time":"2016-03-14 10:00:00","aqi":"87","pm2_5":"64","pm10":"97","co":"0.894","no2":"38.000","o3":"84.000","so2":"23.000","rank":"185"},{"time":"2016-03-14 11:00:00","aqi":"93","pm2_5":"69","pm10":"101","co":"0.863","no2":"37.000","o3":"98.000","so2":"24.000","rank":"218"},{"time":"2016-03-14 12:00:00","aqi":"98","pm2_5":"73","pm10":"111","co":"0.872","no2":"33.000","o3":"113.000","so2":"22.000","rank":"247"},{"time":"2016-03-14 13:00:00","aqi":"113","pm2_5":"85","pm10":"128","co":"0.872","no2":"32.000","o3":"155.000","so2":"22.000","rank":"295"},{"time":"2016-03-14 14:00:00","aqi":"123","pm2_5":"93","pm10":"139","co":"0.893","no2":"33.000","o3":"141.000","so2":"22.000","rank":"314"},{"time":"2016-03-14 15:00:00","aqi":"130","pm2_5":"99","pm10":"147","co":"0.866","no2":"32.000","o3":"147.000","so2":"20.000","rank":"326"},{"time":"2016-03-14 16:00:00","aqi":"137","pm2_5":"104","pm10":"155","co":"0.843","no2":"34.000","o3":"151.000","so2":"19.000","rank":"337"},{"time":"2016-03-14 17:00:00","aqi":"143","pm2_5":"109","pm10":"162","co":"0.833","no2":"38.000","o3":"147.000","so2":"19.000","rank":"340"},{"time":"2016-03-14 18:00:00","aqi":"144","pm2_5":"110","pm10":"162","co":"0.864","no2":"46.000","o3":"137.000","so2":"19.000","rank":"342"},{"time":"2016-03-14 19:00:00","aqi":"144","pm2_5":"110","pm10":"162","co":"0.884","no2":"56.000","o3":"118.000","so2":"17.000","rank":"337"},{"time":"2016-03-14 20:00:00","aqi":"147","pm2_5":"112","pm10":"168","co":"0.914","no2":"74.000","o3":"90.000","so2":"16.000","rank":"336"},{"time":"2016-03-14 21:00:00","aqi":"143","pm2_5":"109","pm10":"169","co":"0.910","no2":"70.000","o3":"79.000","so2":"15.000","rank":"325"},{"time":"2016-03-14 22:00:00","aqi":"134","pm2_5":"102","pm10":"158","co":"0.851","no2":"60.000","o3":"79.000","so2":"16.000","rank":"298"}]}杭州</code>就是所要的数据了。
引用 radio:感谢,真是帮大忙了,这是取得了数据接口么
可以从 XXXXXXXXXXXXXXXXXXXXXX/api/getdata_XXXXXXXXXXXXXp 这里获得数据
用post方法向这个地址传送以下参数:
city:"5p2t5bee" //"杭州"的ba...
<code class="lang-python"># -*- coding:utf8 -*- import urllib2,urllib,random,string,base64,time,datetime,re import string timestart = datetime.datetime.strptime('2016-01-01 20:00:00', '%Y-%m-%d %H:%M:%S') #开始时间 timeend = datetime.datetime.strptime('2016-02-10 20:00:00', '%Y-%m-%d %H:%M:%S') #结束时间 timenow = timestart fileo=open('./data.txt','w')#输出文件 dataa = {} dataa['city'] = '5p2t5bee' dataa['type'] = 'SE9VUg==' while(timenow<timeend): 20100101 dataa['starttime']="base64.encodestring(timenow.strftime('%Y-%m-%d" %h:%m:%s')) timenow="timenow+datetime.timedelta(days=1)" dataa['endtime']="base64.encodestring((timenow-datetime.timedelta(hours=1)).strftime('%Y-%m-%d" f="urllib2.Request(" url ="http://www.aqistudy.cn/api/getdata_citydetail.php" , headers="{" 'host' : 'www.aqistudy.cn', 'user-agent' 'mozilla 5.0 (x11; ubuntu; linux x86_64; rv:44.0) gecko firefox 44.0', 'accept' 'text html,application xhtml+xml,application xml;q="0.9,*/*;q=0.8'," 'accept-language' 'zh-cn,zh;q="0.8,en-US;q=0.5,en;q=0.3'," 'connection' 'keep-alive' }, data ="urllib.urlencode(dataa)" ) r="urllib2.urlopen(f)" outline="base64.decodestring(base64.decodestring(r.read())).replace('{','\n').replace('"total":24,"rows":[','').replace(']','" ').replace('}',' ').replace('\"',' ').replace('杭州',' ') print outline fileo.write(outline) fileo.close()< code></timeend):></code>
<code class="lang-text">time : 2016-01-01 20:00:00 , aqi : 135 , pm2_5 : 103 , pm10 : 150 , co : 1.155 , no2 : 93.000 , o3 : 23.000 , so2 : 22.000 , rank : 200 , time : 2016-01-01 21:00:00 , aqi : 133 , pm2_5 : 101 , pm10 : 154 , co : 1.159 , no2 : 95.000 , o3 : 16.000 , so2 : 22.000 , rank : 185 , time : 2016-01-01 22:00:00 , aqi : 139 , pm2_5 : 106 , pm10 : 162 , co : 1.228 , no2 : 97.000 , o3 : 10.000 , so2 : 22.000 , rank : 202 , time : 2016-01-01 23:00:00 , aqi : 148 , pm2_5 : 113 , pm10 : 180 , co : 1.343 , no2 : 99.000 , o3 : 7.000 , so2 : 21.000 , rank : 215 , time : 2016-01-02 00:00:00 , aqi : 175 , pm2_5 : 132 , pm10 : 208 , co : 1.380 , no2 : 100.000 , o3 : 6.000 , so2 : 19.000 , rank : 250 , time : 2016-01-02 01:00:00 , aqi : 189 , pm2_5 : 142 , pm10 : 225 , co : 1.422 , no2 : 99.000 , o3 : 7.000 , so2 : 20.000 , rank : 277 , time : 2016-01-02 02:00:00 , aqi : 196 , pm2_5 : 147 , pm10 : 234 , co : 1.495 , no2 : 99.000 , o3 : 7.000 , so2 : 19.000 , rank : 291 , time : 2016-01-02 03:00:00 , aqi : 196 , pm2_5 : 147 , pm10 : 230 , co : 1.486 , no2 : 93.000 , o3 : 6.000 , so2 : 20.000 , rank : 298 , time : 2016-01-02 04:00:00 , aqi : 189 , pm2_5 : 142 , pm10 : 218 , co : 1.452 , no2 : 89.000 , o3 : 7.000 , so2 : 19.000 , rank : 292 , time : 2016-01-02 05:00:00 , aqi : 185 , pm2_5 : 139 , pm10 : 212 , co : 1.427 , no2 : 88.000 , o3 : 7.000 , so2 : 19.000 , rank : 283 , time : 2016-01-02 06:00:00 , aqi : 179 , pm2_5 : 135 , pm10 : 206 , co : 1.449 , no2 : 85.000 , o3 : 8.000 , so2 : 18.000 , rank : 275 , time : 2016-01-02 07:00:00 , aqi : 172 , pm2_5 : 130 , pm10 : 198 , co : 1.469 , no2 : 81.000 , o3 : 9.000 , so2 : 18.000 , rank : 265 , time : 2016-01-02 08:00:00 , aqi : 172 , pm2_5 : 130 , pm10 : 192 , co : 1.517 , no2 : 79.000 , o3 : 9.000 , so2 : 17.000 , rank : 262 , time : 2016-01-02 09:00:00 , aqi : 172 , pm2_5 : 130 , pm10 : 200 , co : 1.576 , no2 : 83.000 , o3 : 11.000 , so2 : 19.000 , rank : 249 , time : 2016-01-02 10:00:00 , aqi : 179 , pm2_5 : 135 , pm10 : 208 , co : 1.656 , no2 : 92.000 , o3 : 16.000 , so2 : 25.000 , rank : 241 , time : 2016-01-02 11:00:00 , aqi : 166 , pm2_5 : 126 , pm10 : 198 , co : 1.479 , no2 : 94.000 , o3 : 26.000 , so2 : 27.000 , rank : 220 , time : 2016-01-02 12:00:00 , aqi : 148 , pm2_5 : 113 , pm10 : 176 , co : 1.257 , no2 : 88.000 , o3 : 40.000 , so2 : 26.000 , rank : 197 , time : 2016-01-02 13:00:00 , aqi : 120 , pm2_5 : 91 , pm10 : 141 , co : 1.072 , no2 : 73.000 , o3 : 57.000 , so2 : 20.000 , rank : 168 , time : 2016-01-02 14:00:00 , aqi : 108 , pm2_5 : 81 , pm10 : 122 , co : 0.992 , no2 : 66.000 , o3 : 62.000 , so2 : 18.000 , rank : 168 , time : 2016-01-02 15:00:00 , aqi : 94 , pm2_5 : 70 , pm10 : 106 , co : 0.948 , no2 : 64.000 , o3 : 63.000 , so2 : 18.000 , rank : 149 , time : 2016-01-02 16:00:00 , aqi : 89 , pm2_5 : 66 , pm10 : 102 , co : 0.902 , no2 : 63.000 , o3 : 60.000 , so2 : 18.000 , rank : 146 , time : 2016-01-02 17:00:00 , aqi : 90 , pm2_5 : 67 , pm10 : 106 , co : 0.999 , no2 : 82.000 , o3 : 42.000 , so2 : 16.000 , rank : 144 , time : 2016-01-02 18:00:00 , aqi : 107 , pm2_5 : 80 , pm10 : 133 , co : 1.336 , no2 : 113.000 , o3 : 18.000 , so2 : 15.000 , rank : 162 , time : 2016-01-02 19:00:00 , aqi : 127 , pm2_5 : 96 , pm10 : 171 , co : 1.625 , no2 : 122.000 , o3 : 10.000 , so2 : 15.000 , rank : 169 time : 2016-01-02 20:00:00 , aqi : 140 , pm2_5 : 107 , pm10 : 194 , co : 1.775 , no2 : 121.000 , o3 : 11.000 , so2 : 17.000 , rank : 175 , time : 2016-01-02 21:00:00 , aqi : 153 , pm2_5 : 117 , pm10 : 220 , co : 2.235 , no2 : 119.000 , o3 : 10.000 , so2 : 17.000 , rank : 186 , time : 2016-01-02 22:00:00 , aqi : 160 , pm2_5 : 122 , pm10 : 228 , co : 2.153 , no2 : 118.000 , o3 : 10.000 , so2 : 17.000 , rank : 202 , time : 2016-01-02 23:00:00 , aqi : 159 , pm2_5 : 121 , pm10 : 227 , co : 2.097 , no2 : 114.000 , o3 : 8.000 , so2 : 15.000 , rank : 202 ,</code>
引用 novakon:最近在自学JS和PYTHON,解决的问题和楼主的正好相反,别人的软件采集的数据用数据库转发过来,我做个数据可视化的网页,以前别人用C++写的图表超丑,JAVASCRIPT的插件好多做出来的效果看起来都高大上。
是的,取得了API,或者叫“数据接口”。
楼主可以扩展阅读一下HTTP协议,和base64编码。
所有的编程语言(比如楼上python)都可以解决这两个问题,甚至可以写JS,在浏览器里运行。
引用 smith:我最近就在研究这个,握个爪
百度公司有个开源的前端js图表制作库叫做echat,介绍在这里XXXXXXXXXXXXXXXXXXXXXXXX/
这个,算是百度公司为数不多的良心产品吧
我有玩得比较好的同学在百度公司里面,百度公司除了卖贴吧之外还是有不少有用的东西的
引用 radio:这个python脚本我应该在那种环境下运行?python里,还是其他地方?
# -*- coding:utf8 -*-
import urllib2,urllib,random,string,base64,time,datetime,re
import string
timestart = datetime....
引用 huojunan2:[s::L]肯定是PYTHON里啊
这个python脚本我应该在那种环境下运行?python里,还是其他地方?
引用 radio:谢谢
不好意思没看清主贴。。楼主要获取北京的数据得把第10行的'5p2t5bee'改成‘北京’的编码'5YyX5Lqs'才行蛤
29行的'杭州'也换成'北京'
引用 radio:post方法能讲解下么?
可以从 XXXXXXXXXXXXXXXXXXXXXX/api/getdata_XXXXXXXXXXXXXp 这里获得数据
用post方法向这个地址传送以下参数:
city:"5p2t5bee" //"杭州"的ba...
时段 | 个数 |
---|---|
{{f.startingTime}}点 - {{f.endTime}}点 | {{f.fileCount}} |
200字以内,仅用于支线交流,主线讨论请采用回复功能。