我正在尝试使用 mshtml 检索页面上的图像。在两台不同的机器上工作(都是 Win7-64 位)给了我不同的结果。其中一台机器运行良好。但是,第二个无法读取图像的宽度/高度属性。所有的高度/宽度都是零。
public JsonResult GetHtml(string url)
{
var client = new WebClient();
var htmlCode = client.DownloadString(url);
var htmlDocument = new mshtml.HTMLDocument() as mshtml.IHTMLDocument2;
htmlDocument.write(htmlCode);
var htmlImages = htmlDocument.body.all.tags("img");
var listImages = new List<HtmlImage>();
foreach (var htmlImage in htmlImages)
{
Console.Out.WriteLine("Src: {0}", htmlImage.src);
Console.Out.WriteLine("Width: {0}", htmlImage.width);
Console.Out.WriteLine("Height: {0}", htmlImage.height);
}
}
工作正常的机器使用 MSDN Visual Studio 2010。没有给我正确结果的机器使用 Visual Studio Express Edition 2010。
我将非常感谢任何帮助:如何获得两台机器上图像的大小?