如何从活动的浏览器窗口中读取页面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