C#获取指定网页HTML源码

2024-12-12 06:24:52
推荐回答(2个)
回答1:

public string GetHtmlString(string url)
{
WebRequest wr = WebRequest.CreateHttp(url);
WebResponse res = wr.GetResponse();
Stream st = res.GetResponseStream();
StreamReader sr = new StreamReader(st, Encoding.UTF8);
string GetHtml = sr.ReadToEnd();
st.Close();
sr.Close();
return GetHtml;
}

回答2:

你的意思是获取页面html部分的内容吧