我做了一个爬虫程序,能够爬普通的网页,但是不能爬论坛(比如CSDN),即使我登陆了之后程序也没有权限爬论坛,求好心人给我指条明路,大概是怎么实现?

解决方案 »

  1.   

    可以爬别的网站吗?
    有的论坛是有安全限制的,比方银行的网站
    至于CSDN为什么不能Crawl,不是很清楚
      

  2.   

    应该是你的程序写的有问题
    csdn是可以被爬到的吧,它好象是生成标准静态的
      

  3.   

    csdn是不可以爬的,应该是有一些前台设置的!不让抓取的
      

  4.   

    csdn可能不太确切,因为不用登陆也可以访问。我要爬的是需要登录的网站,就比如说要里面的某个页,但获取的页面源代码是登陆页的源码。我想应该是session或者cookie的问题,但不知道实现方式。
      

  5.   

    如何用java获取某个论坛的cookie呢
      

  6.   

    HttpClient client = new HttpClient();
        client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT);    //登录
        PostMethod post = new PostMethod(
            "http://reg.163.com/logins.jsp?type=1&url=http://fm163.163.com/coremail/fcg/ntesdoor2?lightweight=1&verifycookie=1&language=-1&style=16");
        NameValuePair username = new NameValuePair("username", "[email protected]");
        NameValuePair password = new NameValuePair("password", "519081");
        post.setRequestBody(new NameValuePair[] { username, password });
        client.executeMethod(post);
        String responseString = new String(post.getResponseBodyAsString().getBytes(
            "gbk"));
        System.out
            .println("******************************登录页面******************************");
        System.out.println(responseString);
        Cookie[] cookies = client.getState().getCookies();
        client.getState().addCookies(cookies);
        post.releaseConnection();就得到cookie了