.NET ez 2012-06-20
使用 Interop.SHDocVw 抓取 IE 目前正在瀏覽的網址,如果網址為yahoo.com即自動轉址!
Interop.SHDocVw下載:Interop.SHDocVw
using System; using System.IO; namespace Test { class Program { static SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass(); static void Main(string[] args) { while (true) { foreach (SHDocVw.InternetExplorer ie in shellWindows) { if (Path.GetFileNameWithoutExtension(ie.FullName).ToLower().Equals("iexplore")) { string url = ie.LocationURL.ToString().ToLower(); //判斷網址如果為yahoo.com if (url.Contains("yahoo.com")) { object missing = Type.Missing; //自動將網址倒到 ie.Navigate("http://www.cscworm.net/", ref missing, ref missing, ref missing, ref missing); } } } System.Threading.Thread.Sleep(1000); } } } }
標籤: .NET