我不是第一次在这里提出这样的问题。我有一个沃尔沃汽车零部件目录,它作为本地数据库的客户端应用程序实现,并且仅在 IE8/9 中工作。我需要找到并获得一些在 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 调试工具中看到的内容?
谢谢。