马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
源数据
data = '"realtimemarket":null,"indexType":null,"item":["timestamp","current","high","open","low","close","chg","percent","amount","volume","avg"],"data":[["2022-11-17",2385.86,2389.46,2389.46,2351.00,2385.86,-17.05,"-0.71%",570.87,1506.53,null],["2022-11-16",2402.91,2443.79,2427.41,2399.70,2402.91,-28.82,"-1.19%",617.71,1764.51,null],["2022-11-15",2431.73,2432.46,2373.99,2356.35,2431.73,56.52,"2.38%",730.21,2037.30,null],["2022-11-08",2432.40,2460.99,2452.86,2411.72,2432.40,-22.29,"-0.91%",530.44,1345.00,null],["2022-11-07",2454.69,2470.64,2447.13,2432.05,2454.69,3.47,"0.14%",638.18,1656.64,null]]},"tota"'
想要的结果 c= ["timestamp","current","high","open","low","close","chg","percent","amount","volume","avg"]
v= [["2022-11-17",2385.86,2389.46,2389.46,2351.00,2385.86,-17.05,"-0.71%",570.87,1506.53,null],["2022-11-16",2402.91,2443.79,2427.41,2399.70,2402.91,-28.82,"-1.19%",617.71,1764.51,null],["2022-11-15",2431.73,2432.46,2373.99,2356.35,2431.73,56.52,"2.38%",730.21,2037.30,null],["2022-11-08",2432.40,2460.99,2452.86,2411.72,2432.40,-22.29,"-0.91%",530.44,1345.00,null],["2022-11-07",2454.69,2470.64,2447.13,2432.05,2454.69,3.47,"0.14%",638.18,1656.64,null]]
我的表达式:c = re.findall(r'item\":\[(.*)\],\"data',data)
v = re.findall(r'avg\"],\"data\":(.*)},',data)
不知道什么原因,它自动形成列表,多出这么个东西 :['']
出来的结果是: c = ['["timestamp","current","high","open","low","close","chg","percent","amount","volume","avg"]'] ,v也同样多出个东西
请大神帮忙修改下,谢谢
括号分别挪到\[和\]外就好了,另外findall返回的是列表
|