# Close down IE plugin.CloseBrowser() puts "\r\nPress Enter to exit"; $stdout.flush gets # page_check_watir.rb文件 # Page Check Ruby and WATIR Example # # For more information about this example please refer to the readme.txt file in the # same directory # require 'win32ole' require 'watir' puts "Enter the URL of the page to check (press enter for www.httpwatch.com):\n"; $stdout. flush url = gets.chomp! if url.empty? url = "www.httpwatch.com" end puts "\nChecking " + url + "...\r\n\r\n"; $stdout.flush # Attach HttpWatch control = WIN32OLE.new('HttpWatch.Controller') # Open the IE browser plugin = control.IE.New # Attach Watir to IE browser containing HttpWatch plugin Watir::IE::attach_timeout = 30 ie = Watir::IE.attach(:hwnd, plugin.Container.HWND ) # Start Recording HTTP traffic plugin.Clear() plugin.Log.EnableFilter(false) plugin.Record() # Goto to the URL and wait for the page to be loaded ie.goto(url) # Stop recording HTTP plugin.Stop() if plugin.Log.Pages.Count != 0 printf "\nPage Title: '%s'\n", plugin.Log.Pages(0).Title # Display summary statistics for page summary = plugin.Log.Pages(0).Entries.Summary printf "Total time to load page (secs): %.3f\n", summary.Time printf "Number of bytes received on network: %d\n", summary.BytesReceived printf "HTTP compression saving (bytes): %d\n", summary.CompressionSavedBytes printf "Number of round trips: %d\n", summary.RoundTrips printf "Number of errors: %d\n", summary.Errors.Count end # Close down IE plugin.CloseBrowser(); puts "\r\nPress Enter to exit"; $stdout.flush gets |
C#源代码(pagechecker.cs文件内容):
// Page Check C# Example // // For more information about this example please refer to the readme.txt file in the // same directory // 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 www.httpwatch.com):\r\n"); string url = Console.ReadLine(); if ( url.Length == 0 ) url = "www.httpwatch.com"; Console.WriteLine("\r\nChecking " + url + "...\r\n"); // Create a new instance of HttpWatch in IE Controller control = new Controller(); Plugin plugin = control.IE.New(); // Start Recording HTTP traffic plugin.Log.EnableFilter(false); plugin.Record(); // Goto to the URL and wait for the page to be loaded plugin.GotoURL(url); control.Wait(plugin, -1); // Stop recording HTTP plugin.Stop(); if (plugin.Log.Pages.Count != 0) { Console.WriteLine("\r\nPage Title: '" + plugin.Log.Pages[0].Title + "'"); Console.WriteLine(); // Display summary statistics for page 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); } |