小弟现在要抓取一个网站的内容,但是该网站部分内容需要登陆才能访问,请问如何用程序抓取其内容

解决方案 »

  1.   

    先登录然后再抓啊.
    用HttpWebRequest來收發包 登录与抓取时使用相同的CookieContainer就行了
      

  2.   

    先登录后,再抓
      1、发送HttpRequest请求。
      2、接收HttpResponse返回的结果。得到特定页面的html源文件。
      3、取出包含数据的那一部分源码。
      4、根据html源码生成HtmlDocument,循环取出数据。
      5、写入数据库。
      

  3.   

    首先我想知道你有没有一个合法的用户名和密码来访问这个网站,如果没有,就不用往下看了,hacker的东西我懂得不多。如果你有用户名和密码但是不知道怎么用程序提交身份验证信息,往下看。思路:
    1、搞清楚网站用的是什么身份验证方式,如果是IIS,就有:a) Basic b) Digest c) Integrated Windows Authentication (NTLM or Kerberos)。
    2、参考下面的代码:            string website = "http://localhost";
                string downloadUrl = website + "/Test";            // Create the WebRequest
                WebRequest request = HttpWebRequest.Create(downloadUrl);            CredentialCache cc = new CredentialCache();            // The supported values for authType are "NTLM", "Digest", "Kerberos", and "Negotiate".
                cc.Add(new Uri(website), "NTLM", new NetworkCredential("Username", "Password", "Domain"));            // The Credentials must be specified for the request to pass the server authentication
                // You can use your currently logged-in user credential by the following code:
                // request.Credentials = CredentialCache.DefaultNetworkCredentials;
                request.Credentials = cc;
                
                // Get the response stream and read the stream
                System.IO.StreamReader sr = new System.IO.StreamReader(request.GetResponse().GetResponseStream());
                Console.WriteLine(sr.ReadToEnd());
                sr.Close();
      

  4.   

    先登录然后再抓啊. 
    用HttpWebRequest來收發包   登录与抓取时使用相同的CookieContainer就行了
    ,这种方法最好用,,
      

  5.   

    可否给段代码参考下,怎么样保证“   
    用HttpWebRequest來收發包
    登录与抓取时使用相同的CookieContainer”
      

  6.   


                string website = "http://localhost";
                string downloadUrl = website + "/Test";            // Create the WebRequest
                WebRequest request = HttpWebRequest.Create(downloadUrl);            CredentialCache cc = new CredentialCache();            // The supported values for authType are "NTLM", "Digest", "Kerberos", and "Negotiate".
                cc.Add(new Uri(website), "NTLM", new NetworkCredential("Username", "Password", "Domain"));            // The Credentials must be specified for the request to pass the server authentication
                // You can use your currently logged-in user credential by the following code:
                // request.Credentials = CredentialCache.DefaultNetworkCredentials;
                request.Credentials = cc;
                
                // Get the response stream and read the stream
                System.IO.StreamReader sr = new System.IO.StreamReader(request.GetResponse().GetResponseStream());
                Console.WriteLine(sr.ReadToEnd());
                sr.Close();这个方法就行了
      

  7.   

    分析了对方的服务器是IIS6.0
    假如我抓的是sina网站,参数是不是应该这样:
    website ="www.sina.com";
     Domain应该换成sina
      

  8.   

    保存更新COOKIES.如果有验证码.简单的.可以识别.