獲取谷歌搜尋中任何應用程式中突出顯示文字的第一個網址

獲取谷歌搜尋中任何應用程式中突出顯示文字的第一個網址

有沒有辦法從谷歌獲取突出顯示文字的第一個網址?這就像我們在手機上有鍵盤集成搜索,但在台式機上沒有。

當我想連結到維基百科主題或 stackoverflow 上的軟體網站等時,它特別有用。

答案1

我剛剛創建了一個簡單的方法來做到這一點。這不是最好的,但現在對我來說已經足夠好了。我沒有自訂它來匹配 stackoverflow 的格式,因為我現在希望它靈活。稍後會放到github上。可能需要做得更好才能真正發揮作用。

將以下內容儲存為 Googlesearch.ahk 並使用運行它自動熱鍵

; Search google for the highlighted word
; then get the first link address and put it on the Clipboard

^!r:: Reload

#+g::
    bak = %clipboard%
    Send, ^c
    ;clipboard = %bak%`r`n%clipboard%
    Query = %clipboard%
    wb := ComObjCreate("InternetExplorer.Application")
    ;wb := IEGet()
    wb.Visible := false
    wb.Navigate("www.google.com/search?q=" Query)
    While wb.readyState != 4 || wb.document.readyState != "complete" || wb.busy ; wait for the page to load
      sleep 100
    ; loop % (Nodes := wb.document.getElementById("rso").childNodes).length
    ;     Links_urls .= (A_index = 1) ? Nodes[A_index-1].getElementsByTagName("a")[0].href : "`n" . Nodes[A_index-1].getElementsByTagName("a")[0].href
    ; Msgbox %Links_urls%

    Nodes := wb.document.getElementById("rso").childNodes
    First_link := Nodes[0].getElementsByTagName("a")[0].href
    Clipboard = %First_link%
    TrayTip, First Link on Google Search, %First_link% `r`n Ctrl+V to paste the link
return

相關內容