(1)安装httpwatch;
(2)打开c#工程,在“引用”中增加“COM”组件,在“COM”组件中找到“HttpWatch Professional 7.2 Automation Libary”,确定。(7.2为我安装的httpwatch版本)
(3)copy代码
- using System;
- using HttpWatch;
-
- namespace page_check
- {
- class PageChecker
- {
- [STAThread]
- static void Main(string[] args)
- {
- Console.WriteLine("Enter the URL of the page to check (press enter for http://www.baidu.com/):\r\n");
- string url = Console.ReadLine();
- if ( url.Length == 0 )
- url = "http://www.baidu.com/";
-
- Console.WriteLine("\r\nChecking " + url + "...\r\n");
-
-
- Controller control = new Controller();
- Plugin plugin = control.IE.New();
-
-
- plugin.Log.EnableFilter(false);
- plugin.Record();
-
-
- plugin.GotoURL(url);
- control.Wait(plugin, -1);
-
-
- plugin.Stop();
-
- if (plugin.Log.Pages.Count != 0)
- {
- Console.WriteLine("\r\nPage Title: '" + plugin.Log.Pages[0].Title + "'");
-
- Console.WriteLine();
-
-
- Summary summary = plugin.Log.Pages[0].Entries.Summary;
- Console.WriteLine("Total time to load page (secs): " + summary.Time);
- Console.WriteLine("Number of bytes received on network: " + summary.BytesReceived);
- Console.WriteLine("HTTP compression saving (bytes): " + summary.CompressionSavedBytes);
- Console.WriteLine("Number of round trips: " + summary.RoundTrips);
- Console.WriteLine("Number of errors: " + summary.Errors.Count);
-
- Console.WriteLine("-----------------------",plugin.Log.Entries.Count);
-
-
- for (int i=0; i<plugin.Log.Entries.Count; i++)
- {
- Console.Write(plugin.Log.Entries[i].URL);
- Console.WriteLine(" " + plugin.Log.Entries[i].Time);
- }
- }
-
- plugin.CloseBrowser();
-
- Console.WriteLine( "\r\nPress Enter to exit");
- Console.ReadLine();
- }
- }
- }
(4)运行
完成!
|
请发表评论