using System;
using System.Text;
using System.IO;
using System.Net;
namespace 信息提取
{
    public partial class class1
    {
      string GetWebContent(string Url)
        {
            string strResult = "";
            try
            {
                WebRequest request = WebRequest.Create(Url);
                request.Timeout = 30000;
                request.Headers.Set("Pragma", "no-cache");
                WebResponse response = request.GetResponse();
                Stream streamReceive = response.GetResponseStream();
                StreamReader streamReader = new StreamReader(streamReceive, Encoding.GetEncoding("GB2312"));
                strResult = streamReader.ReadToEnd();
            }
            catch
            {
            }
            return strResult;
        }
       }
}

解决方案 »

  1.   

    楼主这问题应该搬到java版去问@_@
      

  2.   

    package url;import java.io.DataInputStream;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;/**
     * <p>
     * Title:
     * </p>
     * 
     * <p>
     * Description:
     * </p>
     * 
     * <p>
     * Copyright: Copyright (c) 2006
     * </p>
     * 
     * <p>
     * Company:
     * </p>
     * 
     * @author not attributable
     * @version 1.0
     */
    public class TestUrl {
    public TestUrl() {
    } public static void main(String[] argv) {
    URL url = null;
    try {
    url = new URL("http://www.sina.com.cn");
    URLConnection urlConn = url.openConnection();
    DataInputStream din = new DataInputStream(urlConn.getInputStream());
    byte[] buf = new byte[1024];
    int length = din.available();
    System.out.println("######" + length + "######");
    int readlength = 0;
    while (true) {
    readlength += din.read(buf);
    System.out.print(new String(buf));
    if (readlength >= length) {
    break;
    }
    }
    System.out.println("\n######" + readlength + "######");
    } catch (MalformedURLException ex) {
    } catch (IOException ex) {
    }
    }
    }
    类似代码
      

  3.   

    上面那段已经解决了,能不能再问一下
                WebBrowser webb = new WebBrowser();
                webb.Navigate("about:blank");
                HtmlDocument htmldoc = webb.Document.OpenNew(true);
                htmldoc.Write(strDetail);
                HtmlElementCollection htmlTR = htmldoc.GetElementsByTagName("TR");
                foreach (HtmlElement tr in htmlTR)
                {
                   .....
                }
      

  4.   

    package url;import java.io.DataInputStream;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;/**
     * <p>
     * Title:
     * </p>
     * 
     * <p>
     * Description:
     * </p>
     * 
     * <p>
     * Copyright: Copyright (c) 2006
     * </p>
     * 
     * <p>
     * Company:
     * </p>
     * 
     * @author not attributable
     * @version 1.0
     */
    public class TestUrl {
        public TestUrl() {
        }    public static void main(String[] argv) {
            URL url = null;
            try {
                url = new URL("http://www.sina.com.cn");
                URLConnection urlConn = url.openConnection();
                DataInputStream din = new DataInputStream(urlConn.getInputStream());
                byte[] buf = new byte[1024];
                int length = din.available();
                System.out.println("######" + length + "######");
                int readlength = 0;
                while (true) {
                    readlength += din.read(buf);
                    System.out.print(new String(buf));
                    if (readlength >= length) {
                        break;
                    }
                }
                System.out.println("\n######" + readlength + "######");
            } catch (MalformedURLException ex) {
            } catch (IOException ex) {
            }
        }
    }