我已经来过这里了:
- C# get URL from firefox but don't use DDE
- How can I get URLs of open pages from Chrome and Firefox?
- C# - Get all open browsing tabs in all instances of firefox
- https://social.msdn.microsoft.com/Forums/vstudio/en-US/93001bf5-440b-4a3a-ad6c-478a4f618e32/how-can-i-get-urls-of-open-pages-from-chrome-and-firefox?forum=csharpgeneral
- Get Firefox URL?
我知道已经有很多关于这个主题的问题,但没有一个能正确回答。我很好奇如何获取 Firefox 中所有打开页面的 URL,但我找不到提供工作代码的解决方案。
这是互联网上最有值(value)的解决方案,但对我不起作用。 此代码使用 DDE(它使用 NDDE - 一个很好的 .NET DDE 包装器):
private 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;
}
}
我不关心它是否显示历史记录,是否在第二个 Firefox 窗口中获取打开页面的 URL,我现在想让它保持简单。请不要为我提供其他浏览器的代码,因为它总是特定于浏览器或任何 VB 代码。
最佳答案
即使您使用 Firefox,这也有效 > 49:
System.Windows.Automation.AutomationElement AutomationElement = System.Windows.Automation.AutomationElement.FromHandle(ptr);
System.Windows.Automation.AutomationElement Elm = AutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document));
System.Windows.Automation.AutomationPattern[] BAutomationPattern = Elm.GetSupportedPatterns();
System.Windows.Automation.ValuePattern BValuePattern = (System.Windows.Automation.ValuePattern)Elm.GetCurrentPattern(BAutomationPattern[0]);
CurrentUrlName = BValuePattern.Current.Value.ToString();
关于C# 获取 Firefox 中所有打开页面的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45036668/