从chrome到C#表单应用程序获取打开的URL [英] Get opened urls from chrome to C# forms application

查看:95
本文介绍了从chrome到C#表单应用程序获取打开的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要项目StackOverflow TEAM的帮助,适用于大学项目!我需要将Chrome中打开的所有标签中的所有网址都添加到C#表单应用程序中。然后所有的网址,字符串,将加载到列表框...目前,我正在尝试使用System.Windows.Automation。



主要目标是该项目是为了让所有图像在Chrome中打开,这就是我尝试这种方法的原因,因为我首先需要网址。



我尝试了什么:



流程[] procsChrome = Process.GetProcessesByName(chrome);



foreach(procsChrome中的流程chrome){

// chrome流程必须有一个窗口

if(chrome.MainWindowHandle == IntPtr.Zero){

继续;

}



//找到自动化元素

AutomationElement elm =

AutomationElement.FromHandle(chrome.MainWindowHandle);

AutomationElement elmUrlBar = elm.FindFirst(TreeScope.Descendants,

new PropertyCondition(AutomationElement.NameProperty,地址和searc h

bar));



//如果可以找到,请从URL栏中获取值

if(elmUrlBar!= null){

AutomationPattern [] patterns = elmUrlBar.GetSupportedPatterns();

if(patterns.Length> 0){

ValuePattern val =

(ValuePattern)elmUrlBar.GetCurrentPattern(patterns [0]);

Console.WriteLine(Chrome URL found:+ val.Current.Value);

}

}

}



但我的chrome是葡萄牙语,所以我更改了地址和搜索bar我的语言,只适用于页面标题而不是网址...

Need help with a project StackOverflow TEAM, is for a University project! I need to get all urls from all the tabs opened in Chrome to an C# forms application. Then all the urls, strings, will be load to a listbox... Currently, I'm trying to use System.Windows.Automation.

The main objective of the project is to get all images opened in Chrome, that's why i'm trying this approach, because I need the urls first.

What I have tried:

Process[] procsChrome = Process.GetProcessesByName("chrome");

foreach (Process chrome in procsChrome) {
// the chrome process must have a window
if (chrome.MainWindowHandle == IntPtr.Zero) {
continue;
}

// find the automation element
AutomationElement elm =
AutomationElement.FromHandle(chrome.MainWindowHandle);
AutomationElement elmUrlBar = elm.FindFirst(TreeScope.Descendants,
new PropertyCondition(AutomationElement.NameProperty, "Address and search
bar"));

// if it can be found, get the value from the URL bar
if (elmUrlBar != null) {
AutomationPattern[] patterns = elmUrlBar.GetSupportedPatterns();
if (patterns.Length > 0) {
ValuePattern val =
(ValuePattern)elmUrlBar.GetCurrentPattern(patterns[0]);
Console.WriteLine("Chrome URL found: " + val.Current.Value);
}
}
}

but my chrome is in Portuguese language so I change the "Address and search bar" to my language and only worked for the page titles not for the urls...

推荐答案

1)这不是Stack Overflow。

2)这是你的作业:我们不是为你做的:它是有原因的。它就是为了让你思考你被告知的事情,并试着理解它。它也在那里,以便您的导师可以识别您身体虚弱的区域,并将更多的注意力集中在补救措施上。

如果您遇到特定问题,请询问相关问题,我们会尽力而为帮助。但是我们不打算为你做这一切!

3)我不会尝试通过应用程序进行 - 我会首先查看Chrome扩展程序,因为它可以访问网址/打开的图像更容易 - 然后你必须找到一种方法来与你的应用程序进行通信。 使用入门:构建Chrome扩展程序 - Google Chrome [ ^ ]
1) This is not Stack Overflow.
2) This is your homework: We don't do it for you: it is set for a reason. It is there so that you think about what you have been told, and try to understand it. It is also there so that your tutor can identify areas where you are weak, and focus more attention on remedial action.
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
3) I wouldn't try to do it via an app - I'd look into a Chrome extension first as that can access urls / images that are opened a lot more easily - you then just have to find a way for that to communicate with your app. Getting Started: Building a Chrome Extension - Google Chrome[^]


这篇关于从chrome到C#表单应用程序获取打开的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆