按照需求,必须先用Runtime.exec()方法调用IE打开一个网页,然后再想办法,得到这个网页的源代码。最好不要监控80端口。
请给出程序代码,运行通过后立刻给分。

解决方案 »

  1.   

    既然用了Runtime.exec()就和JAVA 没社么关系了 研究下IE的参数吧
      

  2.   

    IE更不懂了,只要能得到源代码就行,这个到底能不能实现啊?要让java程序得到源代码。
      

  3.   

    Process   process   =   Runtime.getRuntime().exec("cmd.exe   /c   start   http://www.csdn.net");
    如果是本地html文件:   
      try{   
      Process   process   =   Runtime.getRuntime().exec("cmd.exe   /c   start   Noname.html");   
      }catch(Exception   e){e.printStackTrace();}
      

  4.   

    关键是,在IE里打开这个网页后,怎么样在JAVA里得到这个网页的源代码。
    wacky1020()结贴时再给你分啊,现在不知道怎么加。
      

  5.   

    public   class   IEExecuter   implements   HyperLinkExecutable   
      {   
      jet.util.TempFile   tempFile   =   new   jet.util.TempFile("","~url","url");   
      public   String   execute(java.awt.Component   comp,   String   displayValue,   String   url)   
      {   
      if(url   ==   null   ||   url.length()   ==   0)   
      return   null;   
        
      Runtime   runtime;   
      String   filename;   
        
      runtime   =   Runtime.getRuntime();   
      try{   
      if   (   jet.util.SystemTools.isWinNT   )   //   check   Windows   NT   serial   in   the   future   
      {   
      File   f   =   tempFile.createTempFile();   
      FileOutputStream   fout   =   new   FileOutputStream(f);   
      PrintWriter   dout   =   new   PrintWriter(fout);   
      dout.println("[InternetShortcut]");   
      dout.println("URL="   +   url);   
      dout.println("Modified=F0DB6E5C9293BE0179");   
      dout.close();   
      fout.close();   
      Process   p   =   runtime.exec("cmd   /c   start   "   +   f.getAbsolutePath());   
      p.waitFor();   
      synchronized(this)   
      {   
      try{   
      wait(3000);   
      }catch(Exception   e){   
      }   
      }   
      f.delete();   
      }   
      else   
      {   
      runtime.exec("start   "   +   url);   
      }   
      }   
      catch(Exception   e)   
      {   
      JDebug.WARNING(e);   
      return   e.getMessage();   
      }   
      return   null;   
      }   
      }
      

  6.   

    那就再帮我找找啊,谢谢了。
    Runtime().exec()后只得到一个Process
    不知道,用Runtime().exec()调用IE打开网页后,到底能不能得到网页的源代码。也许这条路行不通呢。
      

  7.   

    Process process = Runtime.getRuntime().exec(...);
    process.getInputStream()不知道这个InputStream会不会有效果???我想你可以使用Socket直接获得指定网页的源代码, 然后"假装"是通过打开IE获得的网页代码...
      

  8.   

    不是吧~读取网页源代码用得着这么费事吗~用HttpClient就可以了呀~public static void testClient(){
            HttpClient client = new HttpClient();
            PostMethod method = new PostMethod("http://www.163.com");
            try{
                int status = client.executeMethod(method);
                if (status == HttpStatus.SC_OK){
                    String resource = method.getResponseBodyAsString();
                    System.out.println(resource);
                }else{
                    System.out.println("读取网页失败Code=[" + status + "]!");
                }
            }catch(Exception e){
                e.printStackTrace();
            }
        }注意:用commons-httpclient-3.0.1.jar的时候,另外4个也少不了commons-logging-adapters-1.1.jar,commons-logging-api-1.1.jar,commons-logging-1.1.jar,commons-codec-1.3.jar,apache官方网站都有下,用最新版就可以了。
      

  9.   

    谢谢各位的回复,但是请注意,网页必须用IE打开。
    我用Runtime().exec("C:/Program Files/Internet Explorer/iexplore.exe " + url)调用IE打开一个网页,然后我要这个网页的源代码。
    还有,我用的是jdk1.5
      

  10.   

    URL url = new URL("http://java.sun.com/index.html");
    //  Get the jar file
            InputStream is = url.openStream();
        
            BufferedReader in = new BufferedReader(
                    new InputStreamReader(is));
            String readLine = in.readLine();;
            while (readLine != null) {
             System.out.println(readLine);
    readLine = in.readLine();
    }
      

  11.   

    使用URL类来获得源代码就是了
      

  12.   

    如何在Java中嵌入IE
    http://blog.csdn.net/bovy/archive/2007/04/09/1557332.aspx
      

  13.   

    晕,不调用ie直接搞代码不好吗?
    如果必须的话你干脆先用Runtime.exec()方法打开ie,然后用url类来获取代码好了