extern crate simple_excel_writer as excel; use excel::*; fn main() -> Result<(), Box<dyn std::error::Error>> { let url: &str = "http://94.push2.eastmoney.com/api/qt/clist/get?cb=jQuery1124040399874179311124_1685159655748&pn=1&pz=6000&po=1&np=1&ut=bd1d9ddb04089700cf9c27f6f7426281&fltt=2&invt=2&wbp2u=|0|0|0|web&fid=f3&fs=m:0+t:6,m:0+t:80,m:1+t:2,m:1+t:23,m:0+t:81+s:2048&fields=f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,f136,f115,f152&_=1685159655749"; let resp: reqwest::blocking::Response = reqwest::blocking::get(url)?; let mut posts: String = resp.text()?; let beta_offset: usize = posts.find('[').unwrap_or(posts.len()); posts.replace_range(..beta_offset, ""); let posts: String = posts.replace(|c| c == '[' || c == ']'|| c == '{' || c == '}' || c == '"' || c == ')' || c == ';', ""); let stock: Vec<&str> = posts.split(',').collect(); println!("1、数据爬取成功······"); let mut wb = Workbook::create("C:/Users/Rover/Desktop/temp.xlsx"); let mut sheet = wb.create_sheet("Sheet0"); wb.write_sheet(&mut sheet, |sheet_writer| { let sw = sheet_writer; sw.append_row(row!["代码", "名称","最新价","涨跌幅%","涨跌额","成交量(手)","成交额","振幅%","最高","最低","今开","昨收","量比","换手率%","市盈率","市净率"])?; for i in (1..=stock.len()).filter(|x| x % 31 == 0){ sw.append_row(row![&stock[i-20][4..], &stock[i-18][4..], &stock[i-30][3..], &stock[i-29][3..], &stock[i-28][3..], &stock[i-27][3..], &stock[i-26][3..], &stock[i-25][3..], &stock[i-17][4..], &stock[i-16][4..], &stock[i-15][4..], &stock[i-14][4..], &stock[i-22][4..], &stock[i-24][3..], &stock[i-23][3..], &stock[i-10][4..] ])?; } sw.append_row(row![()]) }).expect("write excel error!"); wb.close().expect("close excel error!"); println!("2、数据导出成功······reptile\n3、按Enter键结束!!!"); let mut args = String::new(); std::io::stdin().read_line(&mut args)?; Ok(()) }
标签:A股,mut,..,rs,posts,let,row,Rust,stock From: https://www.cnblogs.com/xorover/p/17931885.html