如何从活动的浏览器窗口中读取页面html?浏览器可以是Chrome / IE / Firefox。 [英] How to read page html from active browser window ? Browser can be Chrome/IE/Firefox.

查看:83
本文介绍了如何从活动的浏览器窗口中读取页面html?浏览器可以是Chrome / IE / Firefox。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个C#逻辑,它可以读取活动浏览器窗口的完整页面html。活动的浏览器窗口可以是IE / Chrome / Firefox。 是否可以使用HtmlAgilityPack读取任何浏览器窗口内容。

I need a C# logic , where it can read complete page html of active browser window. Active browser window can be IE/Chrome/Firefox.  Is it possible with HtmlAgilityPack to read any browser window content.

或者是否有其他方法可以实现相同目的。

Or is there any other way to achieve the same.

请尽快建议。

推荐答案

Hello ashanice,

Hello ashanice,

尝试使用Selenium
WebDriver
。只是给你一个建议。这是我之前写的代码。

Try to use Selenium WebDriver. Just give a suggestion for your. Here is the code I wrote before.

var driver = new InternetExplorerDriver(@"D:\Test7\T2\");

driver.Navigate().GoToUrl(@"http://www.google.com");
            
Console.WriteLine( driver.PageSource);

IWebElement demoDiv = driver.FindElement(By.Id("viewport"));

Console.WriteLine(demoDiv.Text);

Console.WriteLine(demoDiv.GetAttribute("innerHTML"));

driver.Quit();

您可以通过不同的网络浏览器获取页面源。在此之前你需要下载网络驱动程序。

You could get page source by difference web browser. And before that your need to download web driver.

祝你好运,

Neil Hu


这篇关于如何从活动的浏览器窗口中读取页面html?浏览器可以是Chrome / IE / Firefox。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆