.NET ez 2012-06-20
使用 Interop.SHDocVw 抓取 IE 目前正在瀏覽的網頁內容 Interop.SHDocVw下載:
Interop.SHDocVw 需先加入以下參考項目:
- Interop.SHDocVw
- Microsoft.mshtml
using System; using System.IO; using mshtml; 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")) { HTMLDocument currentPage = (HTMLDocument)ie.Document; string url = ie.LocationURL.ToString().ToLower(); //網頁網址 string body = currentPage.body.outerHTML.ToString(); //網頁內容 Console.WriteLine(url + "\r\n" + body); } } Console.WriteLine(); System.Threading.Thread.Sleep(1000); } } } }
標籤: .NET