如何使用ASP.NET获取网页内容?我需要编写一个程序来获取网页的HTML,并将其存储到一个字符串变量中。
发布于 2010-12-22 22:37:45
您可以使用WebClient
Using System.Net;
WebClient client = new WebClient();
string downloadString = client.DownloadString("http://www.gooogle.com");
发布于 2010-12-22 22:42:38
我以前遇到过Webclient.Downloadstring的问题。如果你这样做了,你可以尝试这样做:
WebRequest request = WebRequest.Create("http://www.google.com");
WebResponse response = request.GetResponse();
Stream data = response.GetResponseStream();
string html = String.Empty;
using (StreamReader sr = new StreamReader(data))
{
html = sr.ReadToEnd();
}
发布于 2010-12-22 22:34:32
Webclient client = new Webclient();
string content = client.DownloadString(url);
传递您想要获取的页面的URL。您可以使用htmlagilitypack解析结果。
https://stackoverflow.com/questions/4510212
复制相似问题