(在 C# 中以编程方式) 您好,我想跟踪并记录在任何浏览器上触发的所有网络事件和网络 URL。 我知道我们可以在使用本地代理服务器和路由时做到这一点,但我想知道如果没有本地代理服务器而没有路由,我们怎么能做到这一点。
我真正想要开发的是:- C# wpf 应用程序跟踪所有网络事件并将所有数据(URL 名称 + 时间 + 持续时间)转储到数据库中。
最佳答案
类浏览器位置 { 公共(public)结构 URL 详细信息 {
public String URL;
public String Title;
}
public static URLDetails[] InternetExplorer()
{
Process[] pname = Process.GetProcessesByName("iexplore");
if (pname.Length == 0) {
Console.Write("Process is not running ");
}
System.Collections.Generic.List<URLDetails> URLs = new System.Collections.Generic.List<URLDetails>();
var shellWindows = new SHDocVw.ShellWindows();
foreach (SHDocVw.InternetExplorer ie in shellWindows)
URLs.Add(new URLDetails() { URL = ie.LocationURL, Title = ie.LocationName });
return URLs.ToArray();
}
public static string GetChromeUrl(Process process)
{
if (process == null)
throw new ArgumentNullException("process");
if (process.MainWindowHandle == IntPtr.Zero)
return null;
AutomationElement element = AutomationElement.FromHandle(process.MainWindowHandle);
if (element == null)
return null;
AutomationElement edit = element.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Edit));
return ((ValuePattern)edit.GetCurrentPattern(ValuePattern.Pattern)).Current.Value as string;
}
}
类(class)计划
{
static void Main(string[] args)
{
Console.WriteLine("Internet Explorer: ");
(new List<browserlocation.URLDetails>(browserlocation.InternetExplorer())).ForEach(u =>
{
Console.WriteLine("[{0}]\r\n{1}\r\n", u.Title, u.URL);
});
Console.Write("\n press enter to view Chrome current tab URL");
Console.ReadLine();
foreach (Process process in Process.GetProcessesByName("chrome"))
{
string url = browserlocation.GetChromeUrl(process);
if (url == null)
continue;
Console.WriteLine("CH Url for '" + process.MainWindowTitle + "' is " + url);
Console.ReadLine();
}
}
}
关于c# 如何在不使用本地代理服务器的情况下跟踪来自客户端的所有 Web 事件和 Web URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36492701/