赞
踩
全国据说大部分学校采用的都是正方教务的教务系统,个人感觉安全性做的真的不是很好,比起综合教务,安全性差远了,利用爬虫能非常轻易的获得教务的学生照片。
这里只提供图片下载的代码,关于获取图片的url,懂点计算机的都明白(还是要吐槽一下这个教务的安全性),幸亏我们学校用的不是正方系统,不然感觉隐私泄露有点那啥啊!(逃)
public static void download(String urlString, String filename,String savePath) throws Exception {
InputStream inputStream = null;
HttpURLConnection httpURLConnection = null;
try {
URL url = new URL(urlString);
System.out.println(urlString);
httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.setConnectTimeout(10000);
httpURLConnection.setDoInput(true);
httpURLConnection.setRequestMethod("GET");
int responseCode = httpURLConnection.getResponseCode();
System.out.println(responseCode);
if (responseCode == 200) {
// 从服务器返回一个输入流
inputStream = httpURLConnection.getInputStream();
byte[] bs = new byte[1024];
// 读取到的数据长度
int len;
// 输出的文件流
File sf=new File(savePath);
if(!sf.exists()){
sf.mkdirs();
}
OutputStream os = new FileOutputStream(sf.getPath()+"\\"+filename);
// 开始读取
while ((len = inputStream.read(bs)) != -1) {
os.write(bs, 0, len);
}
System.out.println("wancheng");
// 完毕,关闭所有链接
os.close();
inputStream.close();
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。