一个简单的人人爬虫,实现了一键下载好友相册和日志的功能。
一次尝试使用java的正则匹配,这个真的十分强大,如果不是用了这个代码至少还要多好几百行。但是还是初学,技术方面还有点欠缺,在相片名匹配时有可能会多保存些不需要的信息。
登陆界面截图:
别被上面的水印骗了,仅仅是盗用QQ的gif~~~
类定义
相册类
public class Album { private String albumName;// 相册名 private String albumCover;// 相册封面地址 private String url;// 相册地址 private String num;// 相册内相片数量 private boolean lock;// 是否加密 public Album(String albumCover, String num, String url, boolean lock, String albumName) { this.albumCover = albumCover; this.num = num; this.url = url; this.lock = lock; this.albumName = albumName; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((albumName == null) ? 0 : albumName.hashCode()); result = prime * result + ((url == null) ? 0 : url.hashCode()); return result; } public String getAlbumName() { return albumName; } public String getAlbumCover() { return albumCover; } public String getUrl() { return url; } public String getNum() { return num; } public boolean isLock() { return lock; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Album other = (Album) obj; if (albumName == null) { if (other.albumName != null) return false; } else if (!albumName.equals(other.albumName)) return false; if (url == null) { if (other.url != null) return false; } else if (!url.equals(other.url)) return false; return true; } }
相片类
public class AlbumDetail { private String name;//相片名 private String shortUrl;//相片缩略图url private String largeUrl;//相片完整图url private String ord;//相片保存时可能的后续编号 public AlbumDetail(String name,String shortUrl,String largeUrl,String ord){ this.name=name; this.shortUrl=shortUrl; this.largeUrl=largeUrl; this.ord=ord; } public String getOrd() { return ord; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((largeUrl == null) ? 0 : largeUrl.hashCode()); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((shortUrl == null) ? 0 : shortUrl.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; AlbumDetail other = (AlbumDetail) obj; if (largeUrl == null) { if (other.largeUrl != null) return false; } else if (!largeUrl.equals(other.largeUrl)) return false; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; if (shortUrl == null) { if (other.shortUrl != null) return false; } else if (!shortUrl.equals(other.shortUrl)) return false; return true; } public String getName() { return name; } public String getShortUrl() { return shortUrl; } public String getLargeUrl() { return largeUrl; } }
日志类
public class Blog { private String blogName; private String url; private String body; public Blog(String blogName,String url,String body){ this.blogName=blogName; this.url=url; this.body=body; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((blogName == null) ? 0 : blogName.hashCode()); result = prime * result + ((body == null) ? 0 : body.hashCode()); result = prime * result + ((url == null) ? 0 : url.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Blog other = (Blog) obj; if (blogName == null) { if (other.blogName != null) return false; } else if (!blogName.equals(other.blogName)) return false; if (body == null) { if (other.body != null) return false; } else if (!body.equals(other.body)) return false; if (url == null) { if (other.url != null) return false; } else if (!url.equals(other.url)) return false; return true; } public String getBlogName() { return blogName; } public String getUrl() { return url; } public String getBody() { return body; } }
好友类
public class Friend { private String name; private String id; private String image; public Friend(String name,String id,String image){ this.name=name; this.id=id; this.image=image; } public String getName() { return name; } public String getId() { return id; } public String getImage() { return image; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Friend other = (Friend) obj; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; return true; } }
源码下载地址:https://github.com/TedQ/RenRenDownload