【问题标题】:Access Google Chrome Inspect Element with .NET使用 .NET 访问 Google Chrome 检查元素
【发布时间】:2013-01-07 03:34:01
【问题描述】:

我有一个问题,我找不到解决方案。 我的任务是访问 Google Chrome Inspect Element 提供的文本。 例如 - 如果给我一个网页“http://stackoverflow.com”,那么我应该得到位于检查元素中的文本(右键单击->检查元素)。 有谁知道如何在 .NET 中做到这一点?

附:我有一个替代解决方案,但我想最大限度地提高这项任务的有效性。我目前的解决方案是让 .NET 以编程方式打开 Google Chrome,然后使用键盘快捷键访问 Inspect Element 文本。 但我想在后台执行此操作(程序在我做其他事情时做所有事情)。

【问题讨论】:

  • 假设有一种没有键盘快捷键的有效方法。你的“任务”说你不能使用它?
  • 你的任务的最终目的是什么?您真的需要来自 Inspect Element 的确切文本,还是真的只是提取 DOM 属性?第二种情况你也可以直接使用IE查询DOM。
  • 具体来说 - 网页包含一个媒体文件。但是在页面源中你看不到它的链接。但是在检查元素中你可以。这就是为什么我需要访问 Inspect Element throw .NET

标签: c# .net google-chrome


【解决方案1】:

您要下载页面源吗?因为这基本上就是检查元素的作用。如果我错了,请告诉我。

string remoteUri = "http://www.contoso.com/library/homepage/images/";
            string fileName = "ms-banner.gif", myStringWebResource = null;
            // Create a new WebClient instance.
            WebClient myWebClient = new WebClient();
            // Concatenate the domain with the Web resource filename.
            myStringWebResource = remoteUri + fileName;
            Console.WriteLine("Downloading File \"{0}\" from \"{1}\" .......\n\n", fileName, myStringWebResource);
            // Download the Web resource and save it into the current filesystem folder.
            myWebClient.DownloadFile(myStringWebResource,fileName);     
            Console.WriteLine("Successfully Downloaded File \"{0}\" from \"{1}\"", fileName, myStringWebResource);
            Console.WriteLine("\nDownloaded file saved in the following file system folder:\n\t" + Application.StartupPath);

不是我的代码,它来自http://msdn.microsoft.com/en-us/library/ez801hhe.aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-2

然后你可以使用任何函数来读取文件并使用源代码。

【讨论】:

  • 没有。我知道如何下载页面源,问题是页面源不等同于 Inspect 元素。
  • 具体来说 - 网页包含一个媒体文件。但是在页面源中,您看不到它的链接。但是在检查元素中你可以。这就是为什么我需要访问 Inspect Element throw .NET
  • 不要使用c#进行检查的解决方案?
猜你喜欢
  • 1970-01-01
  • 2011-10-03
  • 2011-11-13
  • 1970-01-01
  • 2012-09-07
  • 2012-09-18
  • 1970-01-01
  • 2014-06-14
  • 2011-11-14
相关资源
最近更新 更多