c# Console application Open/Get Url by Browser
C# url 用 浏览器打开、C#获取浏览器的url
static void Main(string[] args) { string file = @"C:\Users\Hero\Desktop\SiteWhitelist.tsv"; string[] lines = System.IO.File.ReadAllLines(file); foreach (var url in lines) { var startInfo = new ProcessStartInfo("firefox.exe", url); Process.Start(startInfo); string getUrl = GetBrowserURL("FireFox"); Thread.Sleep(10000); File.WriteAllText(@"C:\Users\Hero\Desktop\SaveSiteWhitelist.txt", getUrl + Environment.NewLine + File.ReadAllTex (@"C:\Users\Hero\Desktop\SaveSiteWhitelist.txt")); } Console.ReadKey(); } public static string GetBrowserURL(string browser) { try { DdeClient dde = new DdeClient(browser, "WWW_GetWindowInfo"); dde.Connect(); string url = dde.Request("URL", int.MaxValue); string[] text = url.Split(new string[] { "\",\"" }, StringSplitOptions.RemoveEmptyEntries); dde.Disconnect(); return text[0].Substring(1); } catch { return null; } }