在页面上执行
javascript之后,我需要访问HTML文档的DOM.我有以下代码连接到URL并获取文档.
问题是它修改后不会得到DOM
问题是它修改后不会得到DOM
public class CustomBrowser { public CustomBrowser() { // // TODO: Add constructor logic here // } protected string _url; string html = ""; WebBrowser browser; public string GetWebpage(string url) { _url = url; // WebBrowser is an ActiveX control that must be run in a // single-threaded apartment so create a thread to create the // control and generate the thumbnail Thread thread = new Thread(new ThreadStart(GetWebPageWorker)); thread.SetApartmentState(ApartmentState.STA); thread.Start(); thread.Join(); string s = html; return s; } protected void GetWebPageWorker() { browser = new WebBrowser(); // browser.ClientSize = new Size(_width,_height); browser.ScrollBarsEnabled = false; browser.ScriptErroRSSuppressed = true; //browser.DocumentCompleted += browser_DocumentCompleted; browser.Navigate(_url); // Wait for control to load page while (browser.ReadyState != WebBrowserReadyState.Complete) Application.DoEvents(); Thread.Sleep(5000); var documentAsIHtmlDocument3 = (mshtml.IHTMLDocument3)browser.Document.DomDocument; html = documentAsIHtmlDocument3.documentElement.outerHTML; browser.Dispose(); } }
我希望有人可以帮我解决这个问题