通过抓包获取QQ空间相册的真实地址,实现空间相册下载。

news/2025/3/12 12:34:09/

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

在网上找过相关的资料,都不是太全~有些缺漏。所有自己根据网上的再结合自己的修改了下。

1.通过HttpAnalyzerStdV5 分析QQ空间相册的真实地址。一下就是空间相册的地址:

  之前在网上看见只有一个地址,但是通过我的分析,貌似会有很大的问题。比如:某个人的空间相册有些是有设置密码的。也有不设置密码的,那么就无法下载。因为这类的相册是通过另外一个URL解析的。

private static final String albumbase1 = "http://alist.photo.qq.com/fcgi-bin/fcg_list_album?uin=";//如果没有设置密保的相册是通过这个地址访问的private static final String albumbase2 = "http://xalist.photo.qq.com/fcgi-bin/fcg_list_album?uin=";//设置密保的相册是通过这个地址访问的//private static final String photobase = "http://alist.photo.qq.com/fcgi-bin/fcg_list_photo?uin=";private static final String photobase1 = "http://plist.photo.qq.com/fcgi-bin/fcg_list_photo?uin=";private static final String photobase2 = "http://xaplist.photo.qq.com/fcgi-bin/fcg_list_photo?uin=";

 

 

2.程序的main方法:

1.albums集合是所有相册的集合。

2.主要是两个方法一个是得到集合getAlbums 一个是保存相册的 savePhoto

public static void main(String[] args) {PhotoDownLoad pdl = new PhotoDownLoad();String qq = "1315404564";albums = pdl.getAlbums(qq, albumbase1);//先传一个地址进去要是找到不再分析另外一个地址if (albums == null || albums.size() == 0) {albums = pdl.getAlbums(qq, albumbase2);}if (albums == null || albums.size() == 0) {System.out.println("没有获取到相册");}int len = albums.size();System.out.println("相册信息获取成功,用户共有" + len + "个相册.");for (int i = 0; i < len; i++) { // 考虑到相册数量不会很多,相册采用顺序下载,不使用异步下载System.out.println("开始下载第" + (i + 1) + "个相册...");pdl.savePhoto(i, qq);pdl.curIndex = 0;System.out.println("第" + (i + 1) + "个相册下载完成.");}}

3.getAlbums 方法

1.

/*** 获取用户相册** @param qq* @return */public List<Album> getAlbums(String qq, String url) {List<Album> result = new ArrayList<Album>();HttpClient client = new HttpClient();String getUri = url + qq + "&outstyle=2"; // outstyle!=2服务器将以xml的形式返回结果,HttpMethod method = new GetMethod(getUri);method.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,charset);int status = 0;try {status = client.executeMethod(method);if (status != HttpStatus.SC_OK) {System.err.println("发生网络错误!");return null;}} catch (HttpException e) {e.printStackTrace();return null;} catch (IOException e) {e.printStackTrace();return null;}InputStream is = null;BufferedReader br = null;InputStreamReader isr = null;List<String> ids = new ArrayList<String>();List<String> names = new ArrayList<String>();List<Integer> totals = new ArrayList<Integer>();try {is = method.getResponseBodyAsStream();isr = new InputStreamReader(is);br = new BufferedReader(isr);String temp = null;while ((temp = br.readLine()) != null) {if (temp.contains("\"id\" :")) {String id = temp.substring(temp.indexOf("\"id\" :") + 8,temp.length() - 2);ids.add(id);}if (temp.contains("\"name\" :")) {String name = temp.substring(temp.indexOf("\"name\" :") + 10, temp.length() - 3);names.add(name);}if (temp.contains("\"total\" :")) {String total = temp.substring(temp.indexOf("\"total\" :") + 10,temp.length() - 1);totals.add(Integer.parseInt(total));}if (temp.contains("\"left\" :")) {break;}}} catch (IOException e) {e.printStackTrace();} finally {method.releaseConnection();try {br.close();isr.close();is.close();} catch (IOException e) {e.printStackTrace();}}for (int i = 0; i < ids.size(); i++) {Album album = new Album(ids.get(i), names.get(i), totals.get(i));result.add(album);}return result;}

4.下载一个相册。

1.得到一个相册的整个图片。

/*** 下载一个相册的图片** @param index 相册序号*/public void savePhoto(final int index, final String qq) {Album album = albums.get(index);if(album.getName().indexOf("微博")>=0){System.out.println("微博相册不下载");return;}List<Photo> photosTemp = this.getPhotoByAlbum(album, qq, photobase1);if (photosTemp == null || photosTemp.size() == 0) {photosTemp = this.getPhotoByAlbum(album, qq, photobase2);}if (photosTemp == null || photosTemp.size() == 0) {System.out.println("相册信息为空");return;} else {final List<Photo> photos = photosTemp;final int maxThreadCnt = 10; // 每个相册最多开启10个线程进行下载final int total = album.getCnt();int realThreadCnt = total >= maxThreadCnt ? maxThreadCnt : total; // 实际下载一个相册的线程数/*** 线程驱动下载任务** @author  wensefu.jerry.Ling<br/>*         wrote on 2011-1-29*/class DownLoadTask implements Runnable {int id; // 线程标识int pindex;// 下载的图片指针public DownLoadTask(int id, int pindex) {this.id = id;this.pindex = pindex;}public void run() {while (curIndex <= total - 1) {int temp = pindex;pindex = curIndex;curIndex++;Photo photo = photos.get(temp);System.out.println("线程" + (index + 1) + "_" + id + "开始下载第" + (index + 1) + "个相册第" + (pindex + 1) + "张图片...");saveImgFromUrl(photo, qq);System.out.println("线程" + (index + 1) + "_" + id + "完成第" + (index + 1) + "个相册第" + (pindex + 1) + "张图片下载");}}}ExecutorService exec = Executors.newCachedThreadPool();/** 初始化各线程状态 此处给每个线程分配一个下载起始点*/for (int i = 0; i < realThreadCnt; i++) {DownLoadTask task = new DownLoadTask(i + 1, i);exec.execute(task);}exec.shutdown();}}
源代码下载:http://www.oschina.net/code/snippet_557580_12818

转载于:https://my.oschina.net/u/557580/blog/72823


http://www.ppmy.cn/news/334720.html

相关文章

最新采集下载QQ空间相册照片的方法

QQ空间储存了很多人年少时美好的回忆&#xff0c;里面保存了很多珍贵的照片&#xff0c;如果要保存下载&#xff0c;那就太麻烦了&#xff0c;怎么样才能批量保存QQ空间里的相册照片呢&#xff0c;不管是别人的还是自己的相册&#xff0c;只要用这个方法&#xff0c;都能保存。…

免费超大容量相册空间 - 一刻相册

免费超大容量相册空间 - 一刻相册 百度一刻相册介绍改变和对比下载 百度一刻相册介绍 一刻相册——背靠百度网盘品牌&#xff0c;安全性是可以保障的。同时可以导入网盘的照片&#xff0c;能解决百度网盘非要会员才能传视频的问题。整体版面风格简洁&#xff0c;看起来会比较清…

在线相册

An ASP.NET Application to View and Share Photos Online 一个在线观看和共共享相片的Asp.net程序By Greg Ennis This article explains an ASP.NET application to view and share photos online. 这篇文章解释一个在线观看和共享相片的Asp.net的程序。 最后的效果如下&…

用WPF写了一个QQ空间相册下载工具

左边是博客园一个大神的作品。它的源代码地址是 http://download.csdn.net/detail/fwj380891124/4789228 我仅仅是添加了一部分下载相册的代码。连made by darren都没改动。 右边是展示下载到的QQ相册里的图片。是一个WPF的图片浏览器改过的。 两个exe通过发消息实现进程通…

模拟爬虫下载QQ空间相册高清图片

此案例用于下载QQ空间相册原图&#xff0c;保存质量最高的高清图。 一、分析 由于没有学习过爬虫技术&#xff0c;技术能力有限。无法模拟QQ空间登录&#xff0c;只能手工登录QQ空间然后看网页源码进行分析。 观察显示图片与原图的Url发现&#xff0c;他们有着相似的地方。 然…

【python】QQ 空间照片下载器

文章目录 1. 前提2. 安装依赖3. 使用方法3.1 克隆3.2 修改qq 4 问题4.1 解析错误4.2. valid json 问题 这是我fork 关于dslwind/qzone-photo-downloader的小工具&#xff1a;QQ 空间照片下载器项目&#xff0c;但由于时间长久&#xff0c;下载已经失效。因此我对此做了改进修补…

qq相册破解

http://www.gogoqq.com/photos.htm?uin550669&bumid0

QQ空间相册如何批量导出

昨天因为一些照片和资料丢失&#xff0c;希望把QQ空间照片也备份下。网上找了各种软件比如QQ影像之类的&#xff0c;完全不能用。 这里给大家介绍个软件&#xff0c;QQ相册下载器&#xff1a; https://pan.baidu.com/s/1XKWl9TDDFvgJIuOsCDk0zw 密码&#xff1a;2nw…