JAVA & XML & JAVASCRIPT & AJAX & CSS

Web 2.0 技术储备............

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  77 随笔 :: 17 文章 :: 116 评论 :: 0 Trackbacks
很久没把自己做的东西拿出来和大家分享了,今天总算想到可以写一些东西了。嘿嘿
美女图片爬虫程序很简单,就是从目标网站上将一些美女图片抓取下来,并按文件夹的方式归类存放。
现在以 http://www.36mn.com/网站为例,将论坛上面的一个个图片抓取下来慢慢欣赏。

程序说明:
com.th.spider.Main 运行这个抓取美女图片
com.th.spider.test.* 样例程序
com.th.spider.CookieLogin 模拟登陆实例
com.th.spider.Clean 清除没图片的目录和无效图片目录

用技术创造快感!!!! 嘿嘿


下载资源:
图片抓取代码.zip         网络爬虫原理与实战PPT.zip

主要技术:
Jsoup、HttpClient.

配置说明:
config.properties

#保存目录
save.dir=D:/GIRL
#网站根路径#
url.base=http://www.36mn.com/
#URL访问模板
url.template=http://www.36mn.com/forum-62-#page#.html

#开始PAGE 替换url.template中page参数#
page.start=1
#结束PAGE 替换url.template中page参数#
page.end=2

#线程池大小,并发抓取图片的最大线程数#
thread.pool.size=50

配置中的page.start 和 page.end 指定了抓取论坛开始页到结束页,如果想抓取整个论坛的就page.start=1,page.end=100吧。
配置目录save.dir 默认会创建一个D:/GIRL的目录,用户保存抓取图片。图片保存方式:D:/GIRL/页号/帖子名/图片名

抓取思路:
1.获取论坛中的每个帖子标题和连接。
2.请求帖子连接返回帖子内容。
3.分析获取图片的URL。
4.定位URL下载图片到本地。

论坛帖子列表 http://www.36mn.com/forum-62-1.html

其中一个帖子内容 http://www.36mn.com/thread-22672-1-2.htmll




抓取结果




posted on 2011-06-27 17:07 Web 2.0 技术资源 阅读(4790) 评论(5)  编辑  收藏 所属分类: JAVA原创作品其他东东

评论

# re: [原创]美女图片爬虫程序实战! 2011-06-27 18:45 thebye85
写这种程序真是动力十足啊,哈哈  回复  更多评论
  

# re: [原创]美女图片爬虫程序实战! 2011-06-27 20:16 luobo
用技术创造快感,呵呵  回复  更多评论
  

# re: [原创]美女图片爬虫程序实战! 2011-06-28 08:30 日月雨林@gmail.com
这个就是动力啊!  回复  更多评论
  

# re: [原创]美女图片爬虫程序实战!~用技术创造快感![未登录] 2011-07-01 10:31 杜子
问个问题,当有代理的时候,我用HttpClient 后,用 HttpHost targetHost = new HttpHost(url);
HttpHost proxy = new HttpHost("10.231.96.132", 808);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

HttpGet httpget = new HttpGet("");
HttpResponse response = httpclient.execute(targetHost, httpget);
执行后 System.out.println(response.getStatusLine()); 出现HTTP/1.1 404 /bbs.wed114.cn/data/attachment/forum/201105/08/174414bfl5qf6qfln3q7g3.jpg/& 后面老多个/& 怎么处理。
  回复  更多评论
  

# re: [原创]美女图片爬虫程序实战!~用技术创造快感! 2011-07-01 10:51 Web 2.0 技术资源
2.7. HttpClient proxy configuration
Even though HttpClient is aware of complex routing scemes and proxy chaining, it supports only simple direct or one hop proxy connections out of the box.

The simplest way to tell HttpClient to connect to the target host via a proxy is by setting the default proxy parameter:

DefaultHttpClient httpclient = new DefaultHttpClient();

HttpHost proxy = new HttpHost("someproxy", 8080);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);

One can also instruct HttpClient to use the standard JRE proxy selector to obtain proxy information:

DefaultHttpClient httpclient = new DefaultHttpClient();

ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner(
httpclient.getConnectionManager().getSchemeRegistry(),
ProxySelector.getDefault());
httpclient.setRoutePlanner(routePlanner);

Alternatively, one can provide a custom RoutePlanner implementation in order to have a complete control over the process of HTTP route computation:

DefaultHttpClient httpclient = new DefaultHttpClient();
httpclient.setRoutePlanner(new HttpRoutePlanner() {

public HttpRoute determineRoute(
HttpHost target,
HttpRequest request,
HttpContext context) throws HttpException {
return new HttpRoute(target, null, new HttpHost("someproxy", 8080),
"https".equalsIgnoreCase(target.getSchemeName()));
}

});

  回复  更多评论
  


只有注册用户登录后才能发表评论。


网站导航: