Read source code from tabs in IE/Chrome/Firefox
Using C# and any .NET version I'd like to create a program that can read the source code from any open tab using IE, Firefox or Chrome. Thi开发者_开发百科s is a program that I use for just myself. I haven't been able to find any useful information by Googling this subject.
Thanks!
Maybe it's a bit overkill for using C#. I'd do it using javascript and a bookmarklet, by loading the url and displaying it in an overlay on the page... especially if it's only for yourself.
If you're looking to read "source code" (by this, I assume you mean the HTML source), you could write an app that uses the System.Net.WebClient class, then use the DownloadString() method to pull the source into a string and do whatever you want with it. i.e.
WebClient client = new WebClient();
string html = client.DownloadString("http://your.url.here/");
If you're really looking to integrate with various browsers and try to see what tabs are open, I wouldn't even know where to begin with that one, sorry.
In order to do what you want to do using a C# program you would need some kind of library to automate the browser. This is possible with IE using WATIN, which is really a testing library, but can do this sort of thing. For example,
using WatiN.Core;
...
foreach (IE ie in IE.InternetExplorers())
{
Console.Out.WriteLine(ie.Html);
}
This code snippet is IE specific but version 2.0 (in beta) also works with Firefox. The roadmap does mention support for Chrome but I don't think its implemented yet.
You could also try Selenium, another testing library. It supports all the major browsers though it may be a little more complicated to set up.
精彩评论