在研究一个Android Demo的时候,我发现了Demo里面的图片源很不错,看到这么多的照片,一张张下载太麻烦了,所以我决定用爬虫来爬。

因为本人对Python只有“Hello world”的水平,所以只能用Java来爬取。首先Java对Html的处理有一个很好的开源工具Jsoup

我用的是这个Jar,百度一下就有了。
在Chrome浏览器或者FireFox浏览器按F12,查看网页Html,我们可以发现:

图中画红线的就是每一个界面图片的源啦。然后我们根据源就能下载图片了,所以再写一个下载图片的代码,这样就可以批量下载。

好了,关键代码就有上面这些。

目录为空的啦,现在我们运行
后台输出:

pic文件夹:

爬取成功,本次爬取没有遇到异步,所以相对很简单,如果有兴趣的可以尝试爬取百度图片。
源码地址:https://github.com/Elricyo/SpiderFromMeizi
网友评论
Exception in thread "main" org.jsoup.HttpStatusException: HTTP error fetching URL. Status=514, URL=http://www.mzitu.com/86778/13
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:682)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:629)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:261)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:250)
at com.crawler.image.SpiderUtil.getSrc(SpiderUtil.java:51)
at com.crawler.image.SpiderImageTest.main(SpiderImageTest.java:18)
十分疑惑,Test.java中注释的内容,执行出现异常如上。希望帮忙解答一下。十分感谢!