开发者

WPF Save WebBrowser HTML

开发者 https://www.devze.com 2023-01-19 12:15 出处:网络
Does anyone (please) know how to do this? I 开发者_C百科thought that there would be an easy way to achieve this but can\'t find anything about saving the contents of WebBrowser HTML.You might try some

Does anyone (please) know how to do this? I 开发者_C百科thought that there would be an easy way to achieve this but can't find anything about saving the contents of WebBrowser HTML.


You might try something like this:

(Assuming C# 4 and WPF 4)

dynamic doc = webBrowser.Document;
var htmlText = doc.documentElement.InnerHtml;

Works for me...


Yous should use HttpWebRequest and HttpWebResponse objects. Simple sample (found in web, tested, working):

HttpWebRequest myWebRequest = (HttpWebRequest)HttpWebRequest.Create(@"http://www.[pagename].com");
myWebRequest.Method = "GET";

HttpWebResponse myWebResponse = (HttpWebResponse)myWebRequest.GetResponse();

StreamReader myWebSource = new StreamReader(myWebResponse.GetResponseStream());

string myPageSource = string.Empty;
myPageSource = myWebSource.ReadToEnd();
myWebResponse.Close();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号