爬进gdut新闻网的实现

 /**
         * 配置好CookieStore,让HttpClient自动管理cookies
         */
        CookieStore store=new BasicCookieStore();
        RequestConfig config= RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();
        /**
         * 登录新闻网
         */
        HttpClient client= HttpClients.custom().setDefaultRequestConfig(config).setDefaultCookieStore(store).build();
        HttpPost post=new HttpPost("http://news.gdut.edu.cn/UserLogin.aspx?preURL=http%3a%2f%2fnews.gdut.edu.cn%2fdefault.aspx&__VIEWSTATE=%2FwEPDwUKLTQwOTA4NzE2NmQYAQUeX19Db250cm9sc1JlcXVpcmVQb3N0QmFja0tleV9fFgEFI2N0bDAwJENvbnRlbnRQbGFjZUhvbGRlcjEkQ2hlY2tCb3gxBufpEJuDDaf6eTj0A4Cn2Erf8u98KcGrQqATTB3mEaQ%3D&__EVENTVALIDATION=%2FwEWBQKb37HjDwLgvLy9BQKi4MPwCQL%2BzqO2BAKA4sljg4IvzC7ksG01o7aN0RZUOKEC4lV0bTeXI4zrbaQsj0c%3D&ctl00%24ContentPlaceHolder1%24userEmail=gdutnews&ctl00%24ContentPlaceHolder1%24userPassWord=newsgdut&ctl00%24ContentPlaceHolder1%24CheckBox1=on&ctl00%24ContentPlaceHolder1%24Button1=%E7%99%BB%E5%BD%95");
        HttpResponse response=client.execute(post);
        System.out.println(response.getStatusLine());


        /**
         * 进入具体通知页面
         */
        HttpGet get = new HttpGet("http://news.gdut.edu.cn/ViewArticle.aspx?articleid=144748");
        response = client.execute(get);
        InputStream input=response.getEntity().getContent();
        BufferedReader reader
                =new BufferedReader(
                        new InputStreamReader(
                                input
                        )
        );
        String str,resStr="";
        while ((str=reader.readLine())!=null){
            resStr+=str;
        }
        /**
         * 解析页面
         */
        Document doc=Jsoup.parse(resStr);
        System.out.println(doc.getElementById("content"));
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值