如何用restlet获取网页内容

如何用restlet获取网页内容

1.下载restlet jar包,如果没有可以到:http://download.csdn.net/detail/u012875880/6579179去下载

2.编写java代码如下:

package test;
import java.io.IOException;
import org.restlet.representation.Representation;
import org.restlet.resource.ClientResource;
import org.restlet.resource.ResourceException;
 
public class Client {
    public static void main(String[] args) throws ResourceException, IOException {


    	String url = "http://www.baidu.com/";//设定目标url
    	 ClientResource client = new ClientResource(url);
    	 Representation representation = client.get();
    	 System.out.println(representation.getText());//输出该url对应的网页内容
    }
}


3.运行该程序可以看到百度首页的内容被抓取并显示出来了:


<!DOCTYPE html><!--STATUS OK--><html><head><meta http-equiv="content-type" content="text/html;charset=utf-8"><link rel="dns-prefetch" href="//s1.bdstatic.com"/><link rel="dns-prefetch" href="//t1.baidu.com"/><link rel="dns-prefetch" href="//t2.baidu.com"/><link rel="dns-prefetch" href="//t3.baidu.com"/><link rel="dns-prefetch" href="//t10.baidu.com"/><link rel="dns-prefetch" href="//t11.baidu.com"/><link rel="dns-prefetch" href="//t12.baidu.com"/><title>百度一下,你就知道</title><style >html,body{height:100%}html{overflow-y:auto}#wrapper{position:relative;_position:;min-height:100%}#content{padding-bottom:100px;text-align:center}#ftCon{height:100px;position:absolute;bottom:44px;text-align:center;width:100%;margin:0 auto;z-index:0;overflow:hidden}#ftConw{width:720px;margin:0 auto}body{font:12px arial;text-align:;background:#fff}body,p,form,ul,li{margin:0;padding:0;list-style:none}body,form,#fm{position:relative}td{text-align:left}img{border:0}a{color:#00c}a:active{color:#f60}.bg{background-image:url(http://s1.bdstatic.com/r/www/cache/static/global/img/icons_92966890.png);background-repeat:no-repeat;_background-image:url(http://s1.bdstatic.com/r/www/cache/static/global/img/icons_9d6bd86c.gif)}.c-icon{display:inline-block;width:14px;height:14px;vertical-align:text-bottom;font-style /html><!--9fc0167724cbf240-->

。。。。。。。。。。。。。


以上就是“如何用restlet获取网页内容”,希望对大家有帮助!

如果不了解restlet,可以参考:http://blog.csdn.net/zhu_xun/article/details/16838751

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值