码迷,mamicode.com
首页 > 移动开发 > 详细

c# Console application Open/Get Url by Browser

时间:2016-01-25 11:14:24      阅读:201      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/shy-huang/p/5156757.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!