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();
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[].Substring();
}
catch
{
return null;
}
}
上一篇:Java代码优化(长期更新)


下一篇:pandas用法之二