[英]URL works in Browser but not get response from web Client or Web Request
[英]get url from chrome web browser
我試圖從使用C#的Chrome網頁瀏覽器33版獲取網址。 我已經看過並嘗試了不同的建議 - 但到目前為止還沒有運氣。
我嘗試過的事情: AutomationElement - > 使用C#從Google Chrome獲取當前標簽的URL在33版本的Chrome網絡瀏覽器中使用自動化無法找到“地址和搜索欄”元素。 我也嘗試過使用TreeWalker和我發現的唯一元素:
水平滾動條
回少量
少量轉發
垂直滾動條
回少量
少量轉發
“網頁標題......”
系統菜單欄
系統
最小化
恢復
關
NDde - > 從C#windows窗體應用程序中檢索當前URL
NDde.Client.DdeClient dde = new NDde.Client.DdeClient("Chrome", "WWW_GetWindowInfo");
dde.Connect();
NDde.Client.DdeClient dde = new NDde.Client.DdeClient("Chrome", "Chrome_OmniboxView");
dde.Connect();
兩者都無法正常工作......無法連接。
FindWindowEx - >
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
public string GetChromeUrl(Process process)
{
IntPtr handle = IntPtr.Zero;
Process[] procsChrome = Process.GetProcessesByName("chrome");
foreach (Process chrome in procsChrome)
{
// the chrome process must have a window
if (chrome.MainWindowHandle == IntPtr.Zero)
{
continue;
} else
{
handle = chrome.MainWindowHandle;
break;
}
}
IntPtr urlHandle = FindWindowEx(handle, IntPtr.Zero, null, "Address and search bar");
if (urlHandle != IntPtr.Zero)
{
Console.WriteLine("yes!");
}
return "";
}
也不起作用......
我有多遠
所以我使用了UI Spy並檢查在Chrome 33中查找多功能框的名稱。在UI間諜中根本找不到它,但在檢查中我找到了“地址和搜索欄”,其中包含url值我在追問...問題是如何獲取該網址信息?
任何想法?
從AutomationElement鏈接不確定自動化路由在Chrome 33中不起作用的原因; 我在Chrome 35中實現了它,它確實可以正常工作。 一定要使用第一個實現,據說需要350毫秒才能找到URL。 此外,我發現使用TreeScope.Subtree而不是TreeScope.Descendants似乎工作得快一點,雖然我沒有進行定時測試或任何其他。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.