【问题标题】:C# get URLs of all open pages in FirefoxC#获取Firefox中所有打开页面的URL
【发布时间】:2017-12-15 15:23:35
【问题描述】:

我已经来过这里了:

我知道已经有很多关于这个话题的问题,但没有一个能正确回答。我很好奇如何在 Firefox 中获取所有打开页面的 URL,但我没有找到提供工作代码的解决方案。

这是互联网上最有价值的解决方案,但它对我不起作用。 这段代码使用了 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 代码。

【问题讨论】:

  • 为什么不使用与 C# 几乎相同的 VB 代码,如果您正在寻找复制和粘贴解决方案,那么您来错地方了。
  • 我知道,我并不是要获得一个干净的复制粘贴解决方案,这不是编程激情的意义所在。但我对 C# 有点陌生,所以说实话我不知道如何处理 VB。

标签: c# url firefox


【解决方案1】:

即使您使用 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();

【讨论】:

    猜你喜欢
    • 2011-12-10
    • 2017-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    相关资源
    最近更新 更多