SAE分布式网页SaeFetchurl

来源:互联网 发布:mysql 数据库文件类型 编辑:程序博客网 时间:2024/06/10 17:15

SAE提供了一个高效的网页分布式抓取的服务,可与其他网页分析的程序一同使用。

本文仍是用JAVA实现,使用前要导入sae-local-1.1.0.jar,官网有提供下载。


相关的类为 com.sina.sae.fetchurl.SaeFetchurl

示例代码如下

                                //发起POST请求SaeFetchurl fetchUrl = new SaeFetchurl();fetchUrl.setMethod("post");//请求方式Map<String,String> maps = new HashMap<String, String>();maps.put("name1","value1");maps.put("name2","value2");fetchUrl.setPostData(maps);//设置请求参数String result = fetchUrl.fetch("http://softwarehouse.sinaapp.com/");//设置需要抓取的URLrespContent += result;//抓取失败时输出错误码和错误信息System.out.println(fetchUrl.getErrno());System.out.println(fetchUrl.getErrmsg());
如果是需要登录的网页,则需要添加如下代码:

fetchUrl.setHttpAuth(username, password);


更多使用方法,请查看官方文档 http://sae4java.sinaapp.com/doc/com/sina/sae/fetchurl/SaeFetchurl.html

0 0
原创粉丝点击