c# Console application Open/Get Url by Browser
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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; } }
以上是关于c# Console application Open/Get Url by Browser的主要内容,如果未能解决你的问题,请参考以下文章
Win32 Console Application (控制台程序)这个是干嘛的?为啥新手开始要学的这个?