无法通过C#webclient下载网页并通过请求/回复

时间:2016-01-25 09:33:09

标签: c# http webclient

我想下载网页html代码,但是有几个链接有问题。例如:http://www.business-top.info/http://azerizv.az/ 我完全没有使用这个: 1. WebClient:

using (var client = new WebClient())
            {
                client.Encoding = System.Text.Encoding.UTF8;
                string result = client.DownloadString(resultUrl);
                Console.WriteLine(result);
                Console.ReadLine();
            }

2。 Http请求/响应

var request = (HttpWebRequest)WebRequest.Create(resultUrl);
            request.Method = "POST";
            using (var response = (HttpWebResponse)request.GetResponse())
            {
                using (var stream = response.GetResponseStream())
                {
                    StreamReader sr = new StreamReader(stream, Encoding.UTF8);
                    string data = sr.ReadToEnd();
                    Console.WriteLine(data);
                    Console.ReadLine();
                }
            }

有很多这样的链接,所以我无法通过浏览器通过网页的代码手动下载html

1 个答案:

答案 0 :(得分:1)

某些页面分阶段加载。首先,他们加载页面的核心,然后他们评估任何通过AJAX加载更多内容的JavaScript。要抓取这些页面,您需要更多高级内容抓取库,而不仅仅是简单的HTTP请求发送方。

编辑: 以下是关于您现在遇到的同样问题的问题: Jquery Ajax Web page scraping using c#

相关问题