先说结论,可以用遍历的方法获取你所需要的数据。 这个文本文档中的字符串的主要部分其实是一个字典结构。我们把这个字符串稍微格式化一下就能看到,文本中第2-26行是一个,单键值字典, 唯一的key是"typhoonList",value是一个列表,列表中的每一项是一条数据,每条数据也是一个列表,列表的第1、3项就是你需要的数据,这个python 只要学过,想提取出来就不难 typhoon_jsons_list_2021(
{"typhoonList":[[2723975,"nameless","热带低压",null,"20210022",20210022,null,"stop"],
[2724099,"MALOU","玛瑙",2120,"2120",null,"名字来源于:中国澳门 意为:玛瑙","stop"],
[2717929,"NAMTHEUN","南川",2119,"2119",null,"名字来源于:老挝 意为:河","stop"],
[2713966,"KOMPASU","圆规",2118,"2118",20210020,"名字来源于:日本 意为:圆规星座","stop"],
[2713815,"LIONROCK","狮子山",2117,"2117",20210019,"名字来源于:中国香港 意为:香港一座远眺九龙半岛的山峰名称","stop"],
[2707799,"MINDULLE","蒲公英",2116,"2116",null,"名字来源于:朝鲜 意为:一种小黄花,春天开放,蒲公英属,是朝鲜妇女淳朴识礼的象征","stop"],
[2707635,"DIANMU","电母",2115,"2115",20210017,"名字来源于:中国 意为:神化中的雷电之神","stop"],
[2689244,"CHANTHU","灿都",2114,"2114",null,"名字来源于:柬埔寨 意为:一种花","stop"],
[2688277,"CONSON","康森",2113,"2113",null,"名字来源于:越南 意为:古迹","stop"],
[2686219,"OMAIS","奥麦斯",2112,"2112",null,"名字来源于:美国 意为:漫游(Palauan 语)","stop"],
[2681119,"NIDA","妮妲",2111,"2111",null,"名字来源于:泰国 意为:女士名字","stop"],
[2681195,"MIRINAE","银河",2110,"2110",null,"名字来源于:韩国 意为:宇宙的银河","stop"],
[2679495,"LUPIT","卢碧",2109,"2109",20210011,"名字来源于:菲律宾 意为:残酷","stop"],
[2670840,"NEPARTAK","尼伯特",2108,"2108",null,"名字来源于:密克罗尼西亚 意为:著名的勇士(Kosrae 语)","stop"],
[2659831,"CEMPAKA","查帕卡",2107,"2107",20210009,"以其芬芳的花闻名的植物","stop"],
[2659279,"IN-FA","烟花",2106,"2106",null,"名字来源于:中国澳门 意为:烟花","stop"],
[2659097,"nameless","热带低压",null,"20210007",20210007,null,"stop"],
[2659075,"nameless","热带低压",null,"20210006",20210006,null,"stop"],
[2656478,"CHAMPI","蔷琵",2105,"2105",null,null,"stop"],
[2655955,"KOGUMA","小熊\n",2104,"2104",20210004,"小熊星座","stop"],
[2653775,"CHOI-WAN","彩云",2103,"2103",null,null,"stop"],
[2644377,"SURIGAE","舒力基",2102,"2102",null,"一种鹰","stop"],
[2641936,"DUJUAN","杜鹃",2101,"2101",null,null,"stop"]
]
}
)
另外,提供另外一个思路,这种有规律的字符串可以用正则来处理(知识点百度关键字"python 正则")。这里你需要列表的1,3项,比如第一条数据中为:2723975,"nameless","热带低压"。匹配规则很明显是【7位数字,"若干字母和-","若干中文字符"]】,使用这个模式可以匹配到所有的类似 2723975,"nameless","热带低压" 的字符串,剩下的就很简单了,split处理一下就好了~,当然这是我的思路,其实用正则的方法很多,比如你匹配每个列表也行,单独匹配【[7位数字,】获取第1个也行,自己观察规律就好了。具体的解法还是放给楼主自己做吧,多做几次以后遇到同类问题很快就能解决,勤用百度。
|