现在需要某网页中的信息,要求发送一个查询信息,从这个网页中返回数据和提取所需要的数据(简单来说就是从一网页中提取所需内容),利用HTTP协议,用java实现。
    怎么下手啊,没接触过,哪位达人指点指点啊!等...

解决方案 »

  1.   

    没表达清楚你的意思,还有利用HTTP协议,用java实现??到底你需要什么~~~~~~~~~
      

  2.   

    使用HttpClient第三方控件,模拟浏览器的.
    给你一个简单的例子
    上网搜一下HttpClient有很多
    里面有POST GET 方法
    package test;
    import java.io.IOException;
    import org.apache.commons.httpclient.*;
    import org.apache.commons.httpclient.methods.GetMethod;
    import org.apache.commons.httpclient.params.HttpMethodParams;public class GetSample{
      public static void main(String[] args) {
      //构造HttpClient的实例
      HttpClient httpClient = new HttpClient();
      //创建GET方法的实例
      GetMethod getMethod = new GetMethod("http://www.ibm.com");
      //使用系统提供的默认的恢复策略
      getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
        new DefaultHttpMethodRetryHandler());
      try {
       //执行getMethod
       int statusCode = httpClient.executeMethod(getMethod);
       if (statusCode != HttpStatus.SC_OK) {
        System.err.println("Method failed: "
          + getMethod.getStatusLine());
       }
       //读取内容 
       byte[] responseBody = getMethod.getResponseBody();
       //处理内容
       System.out.println(new String(responseBody));
      } catch (HttpException e) {
       //发生致命的异常,可能是协议不对或者返回的内容有问题
       System.out.println("Please check your provided http address!");
       e.printStackTrace();
      } catch (IOException e) {
       //发生网络异常
       e.printStackTrace();
      } finally {
       //释放连接
       getMethod.releaseConnection();
      }
     }
    }
      

  3.   

    就是用JAVA写一程序,搜索某网页里自己需要的内容,然后把搜索到的内容全部列表输出
      

  4.   

    YOUTA,我编译了一下,怎么报错啊,刚学JAVA,不太懂,下面是错误列表C:\DOCUME~1\ADMINI~1\MYDOCU~1>javac GetSample.java
    GetSample.java:3: package org.apache.commons.httpclient does not exist
    import org.apache.commons.httpclient.*;
    ^
    GetSample.java:4: package org.apache.commons.httpclient.methods does not exist
    import org.apache.commons.httpclient.methods.GetMethod;
                                                 ^
    GetSample.java:5: package org.apache.commons.httpclient.params does not exist
    import org.apache.commons.httpclient.params.HttpMethodParams;
                                                ^
    GetSample.java:10: cannot find symbol
    symbol  : class HttpClient
    location: class test.GetSample
      HttpClient httpClient = new HttpClient();
      ^
    GetSample.java:10: cannot find symbol
    symbol  : class HttpClient
    location: class test.GetSample
      HttpClient httpClient = new HttpClient();
                                  ^
    GetSample.java:12: cannot find symbol
    symbol  : class GetMethod
    location: class test.GetSample
      GetMethod getMethod = new GetMethod("http://www.kjlink.com");
      ^
    GetSample.java:12: cannot find symbol
    symbol  : class GetMethod
    location: class test.GetSample
      GetMethod getMethod = new GetMethod("http://www.kjlink.com");
                                ^
    GetSample.java:14: cannot find symbol
    symbol  : variable HttpMethodParams
    location: class test.GetSample
      getMethod.getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
                                         ^
    GetSample.java:15: cannot find symbol
    symbol  : class DefaultHttpMethodRetryHandler
    location: class test.GetSample
        new DefaultHttpMethodRetryHandler());
            ^
    GetSample.java:19: cannot find symbol
    symbol  : variable HttpStatus
    location: class test.GetSample
       if (statusCode != HttpStatus.SC_OK) {
                         ^
    GetSample.java:27: cannot find symbol
    symbol  : class HttpException
    location: class test.GetSample
      } catch (HttpException e) {
               ^
    11 errors
      

  5.   

    “import org.apache.commons.httpclient.*;”
    包没加载进来。
      

  6.   

    为什么加不进来呢?是JDK本身没有需要另外装么?怎么装,哪有?