I want to save the web page source code and I have the following code:
WebBrowser browser = new WebBrowser();
browser.ScriptErrorsSuppressed = true;
int SleepTime = 5000;
loadPage: browser.Navigate("https://google.com");
System.Threading.Thread.Sleep(SleepTime);
MessageBox.Show("browser.Navigae OK");
if(browser.ReadyState == WebBrowserReadyState.Complete)
{
string path = @"htmlCode.txt";
if(browser.Document.Body.Parent.InnerText != null)
{
File.WriteAllText(path, browser.Document.Body.Parent.OuterHtml, Encoding.GetEncoding(browser.Document.Encoding));
MessageBox.Show("Success! htmlCode.txt created");
break;
}
else
{
MessageBox.Show("browser.Document.Body.Parent.InnerText=" + browser.Document.Body.Parent.InnerText);
MessageBox.Show("Failure htmlCode.txt not created");
}
}
if I comment
MessageBox.Show("browser.Navigate OK");
my code it is not working... why?