簡體   English   中英

如何使用CSharp捕獲DOM Explorer

[英]How to capture DOM Explorer with CSharp

在Internet Explorer中,F12可以訪問兩個選項卡:DOM Explorer和DEBUGGER。

這兩個標簽的內容不同,但我不知道它們的區別是什么。

我想捕獲DOM Explorer數據,而不是網頁的DEBUGGER信息。

當我使用以下兩個代碼中的任何一個時,我都捕獲了在調試器中找到的信息,我的問題是:如何捕獲DOM EXPLORER數據以便可以運行REGEX?

代碼1:

            string urlAddress = "https://www.goodgaragescheme.com/pages/map.aspx?loc=CO70AN";

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(urlAddress);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();

            if (response.StatusCode == HttpStatusCode.OK)
            {
                Stream receiveStream = response.GetResponseStream();
                StreamReader readStream = null;

                if (response.CharacterSet == null)
                {
                    readStream = new StreamReader(receiveStream);
                }
                else
                {
                    readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));
                }

                string data = readStream.ReadToEnd();

                System.IO.File.WriteAllText(@"FILENAME.txt", data);

                response.Close();
                readStream.Close();
            }

代碼2:

        using (var client = new System.Net.WebClient())
        {
            var content = client.DownloadString("https://www.goodgaragescheme.com/pages/map.aspx?loc=CO70AN");

            System.IO.File.WriteAllText(@"FILENAME.txt", content);
        }

答案是:

        SHDocVw.InternetExplorer IE = new SHDocVw.InternetExplorer();
        IE.Visible = false;
        IE.Navigate(@"https://www.goodgaragescheme.com/pages/map.aspx?loc=CO70AN");

        System.Threading.Thread.Sleep(5000);

        mshtml.IHTMLDocument2 htmlDoc = IE.Document as mshtml.IHTMLDocument2;
        string content = htmlDoc.body.outerHTML;

        System.IO.File.WriteAllText(@"FILENAME.txt", content);
        System.Console.WriteLine("done");
        System.Console.ReadKey();

持久性FTW。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM