如题,我想用C#写一个能抓取特定网站的内容数据,不知道可不可以实现,知道的帮我下,谢谢~~

解决方案 »

  1.   

    给个参考吧:using System; 
    using System.Net; 
    using System.IO; namespace MakeAGETRequest_charp 

    /// <summary> 
    /// Summary description for Class1. 
    /// </summary> 
    class Class1 

    static void Main(string[] args) 

    string sURL; 
    sURL = "http://www.microsoft.com"; WebRequest wrGETURL; 
    wrGETURL = WebRequest.Create(sURL); WebProxy myProxy = new WebProxy("myproxy",80); 
    myProxy.BypassProxyOnLocal = true; wrGETURL.Proxy = WebProxy.GetDefaultProxy(); Stream objStream; 
    objStream = wrGETURL.GetResponse().GetResponseStream(); StreamReader objReader = new StreamReader(objStream); string sLine = ""; 
    int i = 0; while (sLine!=null) 

    i++; 
    sLine = objReader.ReadLine(); 
    if (sLine!=null) 
    Console.WriteLine("{0}:{1}",i,sLine); 

    Console.ReadLine(); 



      

  2.   

    之前做的抓取 天气预报的代码(VB)供您参考.
    Partial Class weather
        Inherits System.Web.UI.UserControl
        Public web As New System.Net.WebClient
        Public Sub GetWeather()
            'Dim Content1 As ContentPlaceHolder = Master.FindControl("ContentPlaceHolder1")  '找到Content1中的一個控件-1
            Dim Stream1 As Stream
            Try
                Stream1 = web.OpenRead("http://www.121.com.cn/main/index.shtml")
                Dim Read As New StreamReader(Stream1, System.Text.Encoding.GetEncoding("GB2312"))
                Dim SourceHtml As String = Read.ReadToEnd
                Dim TempHtml, ImageUrl
                TempHtml = CStr(SourceHtml)
                TempHtml = Split(TempHtml, "<td height=""22"" class=""section4""><span class=""section8"">")
                TempHtml = Split(TempHtml(1), "</span>")
                'Html = "以下內容來源自深圳市氣象局(www.121.com.cn)<br>" & TempHtml
                Label1.Text = TempHtml(0)            ImageUrl = CStr(SourceHtml)
                ImageUrl = Split(ImageUrl, "<img src=main/../weatherImage/")
                ImageUrl = Split(ImageUrl(1), ".")
                Image1.ImageUrl = "~/main/weatherImage/" & ImageUrl(0) & ".bmp"
                Image1.Visible = True
                HyperLink1.Text = TempHtml(0)
                HyperLink1.NavigateUrl = "weather.aspx"
            Catch ex As Exception
                HyperLink1.Text = "氣象局網站故障中,無法截取資料!"
            End Try    End Sub    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            GetWeather()
        End Sub
    End Class
      

  3.   

    可以的
    private string SendUrl(string Host) 
            { 
                string StrReturn = ""; 
                WebResponse result = null; 
                try 
                { 
                    WebRequest req = WebRequest.Create(Host); 
                    result = req.GetResponse(); 
                    Stream ReceiveStream = result.GetResponseStream(); 
                    Encoding encode = System.Text.Encoding.GetEncoding("GB2312"); 
                    StreamReader sr = new StreamReader(ReceiveStream, encode); 
                    Char[] read = new Char[256]; 
                    int count = sr.Read(read, 0, 256); 
                    while (count > 0) 
                    { 
                        String str = new String(read, 0, count); 
                        StrReturn += str; 
                        count = sr.Read(read, 0, 256); 
                    } 
                } 
                catch (Exception e) 
                { 
                    StrReturn += e.ToString(); 
                    StrReturn += "找不到请求 URI,或者它的格式不正确"; 
                } 
                finally 
                { 
                    if (result != null) 
                    { 
                        result.Close(); 
                    } 
                } 
                return StrReturn.Trim(); 
            } 
      

  4.   

    三楼你 人家要的是 c# ,不是vb看错了