1

我不是第一次在这里提出这样的问题。我有一个沃尔沃汽车零部件目录,它作为本地数据库的客户端应用程序实现,并且仅在 IE8/9 中工作。我需要找到并获得一些在 IE 中显示的职位。

这是 IE 输出的示例: IE 输出示例 它只是一个表格,仅此而已。

这是我在 IE9 调试工具中看到的: IE调试工具输出

IE 向我展示了一个页面的完整布局,我可以在其中看到一个目标表和包含我需要获取的数据的行。

我写了一个简单的类,它应该遍历所有 IE 选项卡并从目标页面获取 HTML:

using System.Globalization;
using System.Text.RegularExpressions;
using SHDocVw;

namespace WebpageHtmlMiner
{
    static class HtmlMiner
    {       
        public static string GetWebpageHtml(string uriPattern)
        {
            var uriRegexPattern = uriPattern;
            var regex = new Regex(uriRegexPattern);
            var shellWindows = new ShellWindows();

            InternetExplorer internetExplorer = null;

            foreach (InternetExplorer ie in shellWindows)
            {
                Match match = regex.Match(ie.LocationURL);
                if (!string.IsNullOrEmpty(match.Value))
                {
                    internetExplorer = ie;
                    break;
                }
            }

            if (internetExplorer == null) 
            {
                return "Target page is not opened in IE";
            }

            var mshtmlDocument = (mshtml.IHTMLDocument2)internetExplorer.Document; 
            var webpageHtml = mshtmlDocument.body.parentElement.outerHTML.ToString(CultureInfo.InvariantCulture);

            return webpageHtml; //profit
        }
    }
}

它似乎工作正常,但是我在 IE 调试工具中看到的不是我在 IE 调试工具中看到的,而是我得到的 HTML 代码,其中包含大量的 javascript 函数并且目标表中没有数据。

有什么方法可以准确地获得我在 IE 调试工具中看到的内容?

谢谢。

4

1 回答 1

-1

您可以在“”选项卡中获取原始源(服务器发送的源)Script(这适用于我的 IE8 和我的 IE10)。

如果您不使用 AJAX,我认为您也可以右键单击页面并选择Display Souce选项。

于 2013-07-03T15:12:36.513 回答