数据 通过rest接口https://c.m.163.com/ug/api/wuhan/app/data/list-total?t=1582418617382 可以获得。
将获得的json数据存成data.json文件。json文件格式很容易找到自己需要的数据,该数据比较全。
pom文件中加依赖jar
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.5.3</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.8</version>
</dependency>
编写数据项代码
import java.text.DecimalFormat;
/**
* Created by zhangxp on 2020/2/23.
*/
public class DataItem implements Comparable<DataItem>{
public String name;
public int confirm;
public int suspect;
public int heal;
public int dead;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getConfirm() {
return confirm>0?confirm:1;
}
public void setConfirm(int confirm) {
this.confirm = confirm;
}
public int getSuspect() {
return suspect;
}
public void setSuspect(int suspect) {
this.suspect = suspect;
}
public int getHeal() {
return heal;
}
public void setHeal(int heal) {
this.heal = heal;
}
public int getDead() {
return dead;
}
public void setDead(int dead) {
this.dead = dead;
}
public int compareTo(DataItem o) {
return confirm-o.confirm;
}
public String toLine(){
StringBuilder sb=new StringBuilder();
sb.append(name);
sb.append("\t"+confirm);
sb.append("\t"+suspect);
sb.append("\t"+heal);
sb.append("\t"+dead);
double d=heal*1.0/getConfirm();
DecimalFormat df = new DecimalFormat("#.##%");
String str = df.format(d);
sb.append("\t"+str);
return sb.toString();
}
}
编写爬取数据代码
import com.google.gson.Gson;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import java.util.HashMap;
import java.util.LinkedHashMap;
public class OJerseyClientGet {
public static String urlget(){
try{
Client client=Client.create();
WebResource webResource =client.resource("https://c.m.163.com/ug/api/wuhan/app/data/list-total?t=1582418617382");
ClientResponse response =webResource.header("Accept", "application/xml")
.header("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36")
.accept("application/json").get(ClientResponse.class);
int code=response.getStatus();
System.out.println("code: "+code);
if(code!=200)
{
return null;
}
String output =response.getEntity(String.class);
// Gson gson=new Gson();
// HashMap<String,Object> aa= gson.fromJson(output, LinkedHashMap.class);
return output;
}catch(Exception e){
throw new RuntimeException("open url exception: ",e);
}
}
public static void main(String[] args)
{
//HashMap<String,Object> aa=urlget();
System.out.println("aaaok :");
}
编写json分析代码
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.*;
import java.util.*;
import java.util.regex.Pattern;
/**
* Created by zhangxp on 2020/2/23.
*/
public class DataAnalysis {
static final String bitcities[]={"北京","上海","广州","深圳"};
static class SortByKey implements Comparator<DataItem>{
public int compare(DataItem o1, DataItem o2) {
// TODO Auto-generated method stub
int ix=0;
double age1 = o1.getHeal() * 1.0 / o1.getConfirm();
double age2 = o2.getHeal() * 1.0 / o2.getConfirm();
ix = age1 < age2 ? 1 : (age1 == age2 ? 0 : -1);
int tt = ix;
if (ix == 0) {
int iy=o2.confirm-o1.confirm;
tt =(iy>0)?1:(iy==0?0:-1);
}
return tt;
}
}
public static boolean isBigCity(String name){
List<String> lst= Arrays.asList(bitcities);
return lst.contains(name);
}
public static void main(String[] args) {
String path="data.json";
String json=readToString(path);
ObjectMapper objectMapper = new ObjectMapper();
try {
Map<String,Object> aa=objectMapper.readValue(json, LinkedHashMap.class);
Map<String,Object> ab=(Map<String,Object>)readPath(aa,"data.areaTree.0");
String name=(String)readPath(ab,"name");
List<Object> shenlst=(List)readPath(ab,"children");
// System.out.println("aaa: "+ ab);
List<DataItem> lst=new ArrayList<DataItem>() ;
List<DataItem> citylst=new ArrayList<DataItem>() ;
List<DataItem> bigcitylst=new ArrayList<DataItem>();
for(Object ob:shenlst){
Map ma=(Map)ob;
DataItem item=getfromMap(ma);
lst.add(item);
if(isBigCity(item.name)){
bigcitylst.add(item);
}
List<Object> shenlst2=(List)readPath(ma,"children");
for(Object ob2:shenlst2) {
Map ma2 = (Map) ob2;
DataItem item2=getfromMap(ma2);
citylst.add(item2);
if(isBigCity(item2.name)){
bigcitylst.add(item2);
}
}
}
SortByKey sbk=new SortByKey();
Collections.sort(lst,sbk);
outputData(lst);
System.out.println("=======bigcity==========");
Collections.sort(bigcitylst,sbk);
outputData(bigcitylst);
System.out.println("=======city==========");
Collections.sort(citylst,sbk);
outputData(citylst);
} catch (IOException e) {
e.printStackTrace();
}
}
public static void outputData( List<DataItem> lst){
// System.out.println("place confirm suspect heal dead healrate");
System.out.println("地方 确诊 疑似 治愈 死亡 治愈率");
for(DataItem di:lst){
System.out.println(di.toLine());
}
}
public static DataItem getfromMap(Map mo){
DataItem item=new DataItem();
item.setName((String)mo.get("name"));
Map mt=(Map)mo.get("total");
item.setConfirm(readPathInt(mt,"confirm"));
item.setSuspect(readPathInt(mt,"suspect"));
item.setHeal(readPathInt(mt,"heal"));
item.setDead(readPathInt(mt,"dead"));
return item;
}
public static int readPathInt(Map mo,String path)
{
int ires=-1;
Integer sd=(Integer)readPath(mo,path);
return sd.intValue();
}
public static Object readPath(Map mo,String path){
String fields[]=path.split("\\.");
Object ob=mo;
Map m1=null;
List a1=null;
for(String fd : fields){
if( ob instanceof Map){
m1=(Map) ob;
ob=m1.get(fd);
}else if( ob instanceof List){
a1=(List) ob;
if(isNumber(fd)){
int index=Integer.parseInt(fd.trim());
ob=a1.get(index);
}else {
}
}
}
return ob;
}
public static boolean isNumber(String str){
Pattern pattern = Pattern.compile("[0-9]*");
return pattern.matcher(str).matches();
}
public static String readToString(String fileName) {
String encoding = "UTF-8";
File file = new File(fileName);
Long filelength = file.length();
byte[] filecontent = new byte[filelength.intValue()];
try {
FileInputStream in = new FileInputStream(file);
in.read(filecontent);
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
return new String(filecontent, encoding);
} catch (UnsupportedEncodingException e) {
System.err.println("The OS does not support " + encoding);
e.printStackTrace();
return null;
}
}
分析结果,截止2020-02-23 08:39:23各省的治愈率
地方 确诊 疑似 治愈 死亡 治愈率
青海 18 0 18 0 100%
西藏 1 0 1 0 100%
甘肃 91 0 76 2 83.52%
宁夏 71 0 56 0 78.87%
上海 335 0 249 3 74.33%
河北 311 0 219 6 70.42%
湖南 1016 0 710 4 69.88%
贵州 146 0 102 2 69.86%
河南 1271 0 867 19 68.21%
山西 132 0 89 0 67.42%
陕西 245 0 163 1 66.53%
江苏 631 0 418 0 66.24%
云南 174 0 115 2 66.09%
江西 934 0 613 1 65.63%
安徽 989 0 637 6 64.41%
海南 168 0 106 4 63.1%
浙江 1205 0 758 1 62.9%
辽宁 121 0 73 1 60.33%
天津 135 0 81 3 60%
澳门 10 0 6 0 60%
吉林 91 0 54 1 59.34%
福建 293 0 170 1 58.02%
重庆 573 0 328 6 57.24%
广东 1342 0 755 6 56.26%
四川 526 0 260 3 49.43%
北京 399 0 189 4 47.37%
黑龙江 480 0 217 12 45.21%
山东 754 0 320 4 42.44%
广西 249 0 105 2 42.17%
内蒙古 75 0 27 0 36%
新疆 76 0 25 2 32.89%
湖北 64084 0 15340 2346 23.94%
香港 74 0 11 2 14.86%
台湾 28 0 2 1 7.14%
各个城市的治愈率
=======city==========
地方 确诊 疑似 治愈 死亡 治愈率
未明确地区 0 0 180 4 18000%
未明确地区 0 0 16 2 1600%
未明确地区 0 0 12 5 1200%
未明确地区 0 0 11 0 1100%
未明确地区 0 0 8 0 800%
未明确地区 0 0 2 0 200%
沈阳 28 0 33 0 117.86%
攀枝花 16 0 16 0 100%
佳木斯 15 0 15 0 100%
西宁 15 0 15 0 100%
天水 12 0 12 0 100%
铜仁 10 0 10 0 100%
湘西自治州 8 0 8 0 100%
衡水 8 1 8 0 100%
延安 8 0 8 0 100%
承德 7 0 7 0 100%
丽江 7 0 7 0 100%
广元 6 0 6 0 100%
吕梁 6 0 6 0 100%
张家界 5 0 5 0 100%
青浦 5 0 5 0 100%
梧州 5 0 5 0 100%
吉林 5 0 5 0 100%
梁平区 4 0 4 0 100%
普洱 4 0 4 0 100%
楚雄 4 0 4 0 100%
陵水 4 0 4 0 100%
黔西南州 4 0 4 0 100%
西青 4 0 4 0 100%
陇南 4 0 4 0 100%
榆林 3 0 3 0 100%
文昌 3 0 3 0 100%
本溪 3 0 3 0 100%
辽阳 3 0 3 0 100%
临夏 3 0 3 0 100%
中卫 3 0 3 0 100%
海北州 3 0 3 0 100%
黔江 2 0 2 0 100%
城口县 2 0 2 0 100%
大兴安岭 2 0 2 0 100%
乐东 2 0 2 0 100%
红桥 2 0 2 0 100%
张掖 2 0 2 0 100%
松原 2 0 2 0 100%
武隆区 1 0 1 0 100%
秀山县 1 0 1 0 100%
阿坝州 1 0 1 0 100%
韩城市 1 0 1 0 100%
临沧 1 0 1 0 100%
琼中县 1 0 1 0 100%
津南 1 0 1 0 100%
营口 1 0 1 0 100%
金昌 1 0 1 0 100%
梅河口 1 0 1 0 100%
阿克苏 1 0 1 0 100%
兵团第七师 1 0 1 0 100%
石嘴山 1 0 1 0 100%
宁东 1 0 1 0 100%
拉萨 1 0 1 0 100%
怀化 40 0 38 0 95%
长宁 13 0 12 0 92.31%
神农架林区 11 0 10 0 90.91%
保定 32 0 29 0 90.62%
廊坊 30 0 27 0 90%
临沂 49 0 44 0 89.8%
运城 19 0 17 0 89.47%
定西 9 0 8 0 88.89%
益阳 59 0 52 0 88.14%
邵阳 102 0 88 1 86.27%
永州 43 0 37 0 86.05%
忠县 21 0 18 0 85.71%
三门峡 7 0 6 1 85.71%
大渡口区 7 0 6 0 85.71%
丹东 7 0 6 0 85.71%
银川 33 0 28 0 84.85%
宝鸡 13 0 11 0 84.62%
大理 13 0 11 0 84.62%
闵行 19 0 16 0 84.21%
汕头 25 0 21 0 84%
徐州 79 0 66 0 83.54%
驻马店 139 0 116 0 83.45%
菏泽 18 0 15 0 83.33%
徐汇 18 0 15 0 83.33%
清远 12 0 10 0 83.33%
镇江 12 0 10 0 83.33%
河北 12 0 10 0 83.33%
邢台 23 0 19 1 82.61%
张家口 34 0 28 0 82.35%
丽水 17 0 14 0 82.35%
咸阳 17 0 14 0 82.35%
芜湖 33 0 27 0 81.82%
邯郸 32 0 26 0 81.25%
兰州 36 0 29 2 80.56%
浦东新区 60 0 48 0 80%
南通 40 0 32 0 80%
西双版纳 15 0 12 1 80%
儋州 15 0 12 0 80%
黔东南州 10 0 8 0 80%
永川 5 0 4 0 80%
鹤岗 5 0 4 0 80%
延边 5 0 4 0 80%
郴州 39 0 31 0 79.49%
杭州 169 0 133 0 78.7%
安庆 83 0 65 0 78.31%
璧山区 9 0 7 0 77.78%
自贡 9 0 7 0 77.78%
南昌 229 0 178 0 77.73%
衡阳 48 0 37 0 77.08%
宁德 26 0 20 0 76.92%
阳江 13 0 10 0 76.92%
开州 21 0 16 1 76.19%
云阳县 25 0 19 0 76%
枣庄 24 0 18 0 75%
渝中 20 0 15 0 75%
太原 20 0 15 0 75%
静安 16 0 12 0 75%
锦州 12 0 9 0 75%
眉山 8 0 6 0 75%
钦州 8 0 6 0 75%
铜川 8 0 6 0 75%
甘南 8 0 6 0 75%
江津 4 0 3 0 75%
河西 4 0 3 0 75%
阳泉 4 0 3 0 75%
白银 4 0 3 0 75%
昌吉州 4 0 3 0 75%
商丘 91 0 68 3 74.73%
福州 71 0 53 1 74.65%
常德 82 0 61 0 74.39%
中山 66 0 49 0 74.24%
惠州 62 0 46 0 74.19%
亳州 108 0 80 0 74.07%
盐城 27 0 20 0 74.07%
扬州 23 0 17 0 73.91%
南阳 155 0 114 3 73.55%
滨州 15 0 11 0 73.33%
石柱县 15 0 11 0 73.33%
新余 130 0 95 0 73.08%
外地来沪 111 0 81 0 72.97%
普陀 11 0 8 0 72.73%
平顶山 58 0 42 1 72.41%
石家庄 29 0 21 0 72.41%
上饶 123 0 88 0 71.54%
衢州 14 0 10 0 71.43%
松江 14 0 10 0 71.43%
虹口 7 0 5 0 71.43%
商洛 7 0 5 0 71.43%
娄底 76 0 54 0 71.05%
金华 55 0 39 0 70.91%
无锡 55 0 39 0 70.91%
常州 51 0 36 0 70.59%
黔南州 17 0 12 0 70.59%
漳州 20 0 14 0 70%
湖州 10 0 7 0 70%
六盘水 10 0 7 1 70%
安阳 53 0 37 0 69.81%
宁波 157 0 109 0 69.43%
宿迁 13 0 9 0 69.23%
曲靖 13 0 9 0 69.23%
万宁 13 0 9 0 69.23%
梅州 16 0 11 0 68.75%
宜春 106 0 72 0 67.92%
泰州 37 0 25 0 67.57%
西安 120 0 81 1 67.5%
台州 146 0 98 0 67.12%
许昌 39 0 26 0 66.67%
广安 30 0 20 0 66.67%
宜宾 12 0 8 0 66.67%
大同 12 0 8 0 66.67%
黄山 9 0 6 0 66.67%
杨浦 9 0 6 0 66.67%
嘉定 9 0 6 0 66.67%
澄迈县 9 0 6 1 66.67%
平凉 9 0 6 0 66.67%
宣城 6 0 4 0 66.67%
黄浦 6 0 4 0 66.67%
龙岩 6 0 4 0 66.67%
琼海 6 0 4 1 66.67%
临高县 6 0 4 0 66.67%
外地来津 6 0 4 0 66.67%
和平 6 0 4 0 66.67%
乐山 3 0 2 0 66.67%
资阳 3 0 2 0 66.67%
金山 3 0 2 0 66.67%
百色 3 0 2 0 66.67%
东方 3 0 2 0 66.67%
定安县 3 0 2 1 66.67%
滨海新区 3 0 2 0 66.67%
庆阳 3 0 2 0 66.67%
巴州 3 0 2 0 66.67%
阜阳 155 0 102 0 65.81%
安康 26 0 17 0 65.38%
抚州 72 0 47 0 65.28%
绍兴 42 0 27 0 64.29%
大足 14 0 9 0 64.29%
巫溪县 14 0 9 0 64.29%
黑河 14 0 9 0 64.29%
玉溪 14 0 9 1 64.29%
湛江 22 0 14 0 63.64%
鄂尔多斯 11 0 7 0 63.64%
宿州 41 0 26 0 63.41%
周口 76 0 48 0 63.16%
聊城 38 0 24 0 63.16%
蚌埠 160 0 101 5 63.12%
漯河 35 0 22 0 62.86%
株洲 80 0 50 0 62.5%
日照 16 0 10 0 62.5%
朔州 8 0 5 0 62.5%
郑州 157 0 98 0 62.42%
信阳 274 0 171 2 62.41%
六安 69 0 43 0 62.32%
赣州 76 0 47 1 61.84%
绥化 47 0 29 4 61.7%
开封 26 0 16 0 61.54%
滁州 13 0 8 0 61.54%
凉山 13 0 8 0 61.54%
新乡 57 0 35 3 61.4%
晋中 36 0 22 0 61.11%
淮安 66 0 40 0 60.61%
昆明 53 0 32 0 60.38%
长春 45 0 27 0 60%
泰安 35 0 21 1 60%
四平 15 0 9 1 60%
韶关 10 0 6 0 60%
巫山县 10 0 6 0 60%
秦皇岛 10 0 6 1 60%
潮州 5 0 3 0 60%
济源 5 0 3 0 60%
固原 5 0 3 0 60%
三亚 54 0 32 1 59.26%
池州 17 0 10 0 58.82%
渝北 17 0 10 0 58.82%
两江新区 17 0 10 0 58.82%
遂宁 17 0 10 0 58.82%
七台河 17 0 10 0 58.82%
沧州 48 0 28 3 58.33%
湘潭 36 0 21 0 58.33%
长沙 242 0 141 2 58.26%
洛阳 31 0 18 0 58.06%
合肥 174 0 101 1 58.05%
温州 504 0 292 1 57.94%
鹤壁 19 0 11 0 57.89%
青岛 59 0 34 1 57.63%
苏州 87 0 50 0 57.47%
宝山 21 0 12 0 57.14%
雅安 7 0 4 0 57.14%
忻州 7 0 4 0 57.14%
呼伦贝尔 7 0 4 0 57.14%
广州 345 0 197 0 57.1%
深圳 417 0 237 3 56.83%
合川 23 0 13 0 56.52%
毕节 23 0 13 0 56.52%
遵义 32 0 18 0 56.25%
昭通 25 0 14 0 56%
万州 118 0 66 4 55.93%
南京 93 0 52 0 55.91%
岳阳 156 0 87 1 55.77%
淮南 27 0 15 0 55.56%
淮北 27 0 15 0 55.56%
荣昌区 9 0 5 0 55.56%
奉贤 9 0 5 0 55.56%
保山 9 0 5 0 55.56%
威海 38 0 21 0 55.26%
九龙坡 20 0 11 1 55%
成都 143 0 78 3 54.55%
绵阳 22 0 12 0 54.55%
玉林 11 0 6 0 54.55%
厦门 35 0 19 0 54.29%
齐齐哈尔 43 0 23 1 53.49%
嘉兴 45 0 24 0 53.33%
河东 15 0 8 0 53.33%
焦作 32 0 17 1 53.12%
桂林 32 0 17 0 53.12%
珠海 98 0 52 1 53.06%
黄冈 2904 0 1540 98 53.03%
南宁 55 0 29 0 52.73%
南充 38 0 20 0 52.63%
肇庆 19 0 10 1 52.63%
长寿 21 0 11 0 52.38%
綦江 23 0 12 0 52.17%
铜陵 29 0 15 0 51.72%
济南 47 0 24 0 51.06%
潍坊 44 0 22 0 50%
马鞍山 38 0 19 0 50%
贵阳 36 0 18 1 50%
吉安 22 0 11 0 50%
垫江县 20 0 10 0 50%
南平 20 0 10 0 50%
舟山 10 0 5 0 50%
晋城 10 0 5 0 50%
揭阳 8 0 4 0 50%
景德镇 6 0 3 0 50%
巴南 6 0 3 0 50%
朝阳 6 0 3 0 50%
公主岭 6 0 3 0 50%
高新区 4 0 2 0 50%
崇明县 4 0 2 0 50%
贺州 4 0 2 0 50%
东丽 4 0 2 0 50%
通化 4 0 2 0 50%
文山州 2 0 1 0 50%
武清 2 0 1 0 50%
临汾 2 0 1 0 50%
恩施州 251 0 123 3 49%
海口 39 0 19 0 48.72%
咸宁 836 0 398 11 47.61%
大连 19 0 9 0 47.37%
天门 494 0 232 13 46.96%
黄石 1001 0 468 29 46.75%
淄博 30 0 14 0 46.67%
渭南 15 0 7 0 46.67%
连云港 48 0 22 0 45.83%
柳州 24 0 11 0 45.83%
泉州 46 0 21 0 45.65%
奉节县 22 0 10 0 45.45%
内江 22 0 10 0 45.45%
鹰潭 18 0 8 0 44.44%
红河 9 0 4 0 44.44%
莆田 55 0 24 0 43.64%
乌鲁木齐 23 0 10 0 43.48%
仙桃 571 0 248 19 43.43%
荆州 1574 0 681 41 43.27%
九江 118 0 51 0 43.22%
佛山 84 0 36 0 42.86%
吴忠 28 0 12 0 42.86%
茂名 14 0 6 0 42.86%
牡丹江 14 0 6 0 42.86%
昌江 7 0 3 0 42.86%
巴中 24 0 10 0 41.67%
葫芦岛 12 0 5 1 41.67%
濮阳 17 0 7 0 41.18%
潜江 191 0 78 8 40.84%
烟台 47 0 19 0 40.43%
十堰 667 0 267 2 40.03%
铜梁区 10 0 4 0 40%
丰都县 10 0 4 0 40%
汕尾 5 0 2 0 40%
涪陵 5 0 2 0 40%
德宏 5 0 2 0 40%
襄阳 1173 0 463 28 39.47%
萍乡 33 0 13 0 39.39%
荆门 918 0 361 37 39.32%
江门 23 0 9 0 39.13%
哈尔滨 198 0 77 3 38.89%
德阳 18 0 7 0 38.89%
双鸭山 52 0 20 3 38.46%
汉中 26 0 10 0 38.46%
随州 1300 0 498 30 38.31%
贵港 8 0 3 0 37.5%
长治 8 0 3 0 37.5%
巴彦淖尔 8 0 3 0 37.5%
包头 11 0 4 0 36.36%
江北 28 0 10 0 35.71%
三明 14 0 5 0 35.71%
唐山 58 0 20 1 34.48%
泸州 24 0 8 0 33.33%
潼南区 18 0 6 0 33.33%
伊犁州 18 0 6 0 33.33%
南岸 15 0 5 0 33.33%
赤峰 9 0 3 0 33.33%
南开 6 0 2 0 33.33%
北辰 6 0 2 0 33.33%
保亭县 3 0 1 0 33.33%
吐鲁番 3 0 1 0 33.33%
乌兰察布 3 0 1 0 33.33%
东莞 94 0 31 1 32.98%
德州 37 0 12 2 32.43%
北海 44 0 14 1 31.82%
达州 41 0 13 0 31.71%
宝坻 60 0 19 1 31.67%
防城港 19 0 6 0 31.58%
宜昌 917 0 289 29 31.52%
孝感 3443 0 1078 102 31.31%
大庆 26 0 8 1 30.77%
鸡西 46 0 14 0 30.43%
鄂州 1379 0 417 40 30.24%
呼和浩特 7 0 2 0 28.57%
河源 4 0 1 0 25%
安顺 4 0 1 0 25%
宁河县 4 0 1 0 25%
兵团第八师石河子市 4 0 1 1 25%
锡林郭勒盟 9 0 2 0 22.22%
武汉 46201 0 8186 1856 17.72%
甘孜州 69 0 12 0 17.39%
河池 25 0 4 1 16%
铁岭 7 0 1 0 14.29%
辽源 7 0 1 0 14.29%
通辽 7 0 1 0 14.29%
沙坪坝 8 0 1 0 12.5%
济宁 257 0 31 0 12.06%
外地来京 26 0 2 0 7.69%
丰台 41 0 3 0 7.32%
石景山 14 0 1 0 7.14%
通州 19 0 1 0 5.26%
大兴 39 0 2 0 5.13%
监狱系统 253 0 3 0 1.19%
海淀 62 0 0 0 0%
朝阳 60 0 0 0 0%
西城 53 0 0 0 0%
省十里丰监狱 36 0 0 0 0%
昌平 29 0 0 0 0%
房山 16 0 0 0 0%
东城 12 0 0 0 0%
来宾 11 0 0 0 0%
盘锦 11 0 0 0 0%
顺义 10 0 0 0 0%
兵团第四师 10 0 0 0 0%
阜新 8 0 0 0 0%
怀柔 7 0 0 0 0%
密云 7 0 0 0 0%
鞍山 4 0 0 0 0%
兵团第九师 4 0 0 1 0%
门头沟 3 0 0 0 0%
兵团第十二师 3 0 0 0 0%
彭水县 2 0 0 0 0%
兵团第六师五家渠市 2 0 0 0 0%
乌海 2 0 0 0 0%
赣江新区 1 0 0 0 0%
酉阳县 1 0 0 0 0%
万盛经开区 1 0 0 0 0%
伊春 1 0 0 0 0%
延庆 1 0 0 0 0%
杨凌示范区 1 0 0 0 0%
白城 1 0 0 0 0%
兴安盟 1 0 0 0 0%
大城市的治愈率
地方 确诊 疑似 治愈 死亡 治愈率
上海 335 0 249 3 74.33%
广州 345 0 197 0 57.1%
深圳 417 0 237 3 56.83%
北京 399 0 189 4 47.37%
python通过rest接口获得json数据。
import urllib3
import json
def readdict(dic,path):
fds=path.split(".")
mo=dic
for fd in fds:
if isinstance(mo,list):
ix=int(fd);
mo=mo[ix]
elif isinstance(mo,dict):
mo=mo[fd]
return mo;
def Write_Text(file_name,contant):
# file_name = 'test.txt'
with open(file_name,"w",encoding='utf-8') as f:
f.writelines(contant)
f.writelines("\n")
class DataItem(object):
name = "kirin"
confirm=0
suspect=0
heal=0
dead=0;
# # self.属性写入 等价于调用dict.__setitem__
__setitem__ = object.__setattr__
# # self.属性读取 等价于调用dict.__setitem__
__getitem__ = object.__getattribute__
def getConfirm(self):
return 1 if self.confirm==0 else self.confirm;
def toLine(self):
sd=self.heal*1.0/self.getConfirm()
sf="{:<10s}\t{:>6d} {:>6d} {:>6d} {:>6d} {:>6.2%}"
print(sf.format(self.name,self.confirm,self.suspect,self.heal,self.dead,sd) )
def outTitle():
sf="{:<10s}\t{:>6s} {:>6s} {:>6s} {:>6s} {:>6s}"
sl=['地方', '确诊', '疑似', '治愈', '死亡', '治愈率']
print(sf.format(sl[0],sl[1],sl[2],sl[3],sl[4],sl[5]))
def dict2DataItem(dictObj):
inst=DataItem();
inst.name=dictObj['name']
total=dictObj['total']
for k, v in total.items():
inst[k] = v
return inst
url = "https://c.m.163.com/ug/api/wuhan/app/data/list-total?t=1582418617382";
http = urllib3.PoolManager()
r = http.request('GET', url,headers={'accept': 'application/json'})
print(r.status)
r.encoding = 'utf-8'
html=r.data.decode( );
#tm=json.decoder(html)
dict1=json.loads(html)
#print(dict1);
print(dict1['msg']);
art=dict1['data']['areaTree'];
print(dict1['data']['areaTree'][0]['name']);
china=readdict(dict1,"data.areaTree.0.name")
print(china)
tm=readdict(dict1,"data.areaTree.0.lastUpdateTime")
aa=tm.split(" ");
print(aa[0])
fp="data"+aa[0]+".json"
Write_Text(fp,html);
fdp="data.json"
Write_Text(fdp,html);
children=readdict(dict1,"data.areaTree.0.children")
def getOutData(children,lkey):
plst=[]
for pe in children:
dt=dict2DataItem(pe)
plst.append(dt)
plst.sort(key=lkey,reverse=True)
#print("地方 确诊 疑似 治愈 死亡 治愈率")
outTitle()
for pe in plst:
pe.toLine()
print(len(plst))
getOutData(children,lkey=lambda x:x.heal/x.getConfirm())
#html = json.dumps(html).encode('utf-8')
#print(html)
print("----------")
children=readdict(dict1,"data.areaTree")
getOutData(children,lkey=lambda x:x.confirm)
python输出如下(2月28日数据),之后类似java处理。
200
成功
中国
中国
2020-02-28
地方 确诊 疑似 治愈 死亡 治愈率
青海 18 0 18 0 100.00%
西藏 1 0 1 0 100.00%
宁夏 72 0 68 0 94.44%
甘肃 91 0 82 2 90.11%
云南 174 0 156 2 89.66%
河南 1272 0 1110 20 87.26%
河北 318 0 277 6 87.11%
江西 935 0 790 1 84.49%
安徽 990 0 831 6 83.94%
山西 133 0 111 0 83.46%
上海 337 0 279 3 82.79%
湖南 1017 0 838 4 82.40%
江苏 631 0 514 0 81.46%
浙江 1205 0 975 1 80.91%
陕西 245 0 198 1 80.82%
福建 296 0 239 1 80.74%
澳门 10 0 8 0 80.00%
海南 168 0 132 5 78.57%
......
山东 756 0 405 6 53.57%
湖北 65914 0 26466 2682 40.15%
香港 94 0 30 2 31.91%
台湾 34 0 6 1 17.65%
34
----------
地方 确诊 疑似 治愈 死亡 治愈率
中国 78962 2308 36393 2791 46.09%
韩国 2337 0 24 13 1.03%
日本 933 0 23 10 2.47%
意大利 653 0 45 17 6.89%
伊朗 388 320 49 34 12.63%
新加坡 93 0 62 0 66.67%
......