Jump to content

How to get text of browser mouseover URL?


Recommended Posts

I'm using Firefox however it shows up in all browsers.  When you hover over a hyperlink and the cursor turns to a hand then in the lower left corner of the browser the actual web URL link pops up.  How does one capture that text programmatically?  I know in FF I can right click and "Copy Link" I'm wondering if there is another way.

Link to comment
Share on other sites

@ahhaRight click and "Copy Link" is good because it's only 2 clicks.

Then things become complicated if you have to click on an empty text file, paste your link in it, then back to FF and copy another link (for later use), back into the text file, paste it etc...

If your goal is to grab several links from here & there for later use, then this is what I do to avoid this "back and forth" move between any Browser and the text file, after launching this script that will automatically record in a text file all changes made to the clipboard when it concerns url's.

#include <MsgBoxConstants.au3>

OnAutoItExitRegister("Close_FileOutput")

$sFilePath = @ScriptDir ; "Only includes a trailing backslash when the script is located in the root of a drive" (help file)
If StringRight($sFilePath, 1) <> "\" Then $sFilePath &= "\"

$sDateTime = @YEAR & "-" & @MON & "-" & @MDAY & " " & @HOUR & "h" & @MIN & "m" & @SEC & "s" ; ex. "2021-11-07 17h52m15s"

$sFileOutput = $sFilePath & $sDateTime & ".txt" ; ex. "C:\Temp\2021-11-07 17h52m15s.txt" if script is in C:\Temp

$hFileOpen = FileOpen($sFileOutput, 2 + 512) ; 2 = Write mode (erase previous contents) . 512 = Ansi

If $hFileOpen = -1 Then
    MsgBox($MB_TOPMOST, "", "An error occurred when OPENING the output file")
    Exit
EndIf

; $sClip_Old = "" ; variable to keep clipboard content, for comparing when its content changes, 1 time per second (or twice)
; ClipPut("")     ; write clipboard (here we write an empty string, which in fact forces the clipboard to become empty)

$sClip_Old = "fill clipboard with any string at start, better than an empty string"
ClipPut($sClip_Old)

While 1
    ; Sleep(1000) ; 1000ms = 1s
    Sleep(500)    ; 500ms  = 0.5s (twice per second seems better, we'll see...)
    $sClip_Get = ClipGet()
    If $sClip_Get <> $sClip_Old Then
        Select
            Case $sClip_Get = "" ; this happens if we choose for example "copy image" in context menu, instead of "copy image adress"
                MsgBox(BitOr($MB_TOPMOST, $MB_ICONINFORMATION) , "Clipboard is empty", "No link was copied   ")
                ClipPut($sClip_Old)

            Case StringLeft($sClip_Get, 4) <> "http" ; do not write in txt file because it's not a url

            Case Else
                $iStatus = FileWriteLine($hFileOpen, $sClip_Get) ; "If the line does NOT end in @CR or @LF then a DOS linefeed (@CRLF) will be automatically added" (help file) => all is good !
                If $iStatus = 0 Then
                    MsgBox($MB_TOPMOST, "", "An error occurred when WRITING the output file")
                    Exit
                EndIf
                $sClip_Old = $sClip_Get
        EndSelect
    EndIf
WEnd

;==============================================================================
Func Close_FileOutput()
    FileClose($hFileOpen)
EndFunc   ;==>Close_FileOutput

Let's hope it will help you to achieve your goal
Good luck
 

Link to comment
Share on other sites

Yes, 2 clicks to add a desired link in the text file. But at least you choose the wanted links by yourself.
I never searched another way to do it because I don't want all links hovered on to automatically fill the text file.
It would require to delete many unwanted links in the text file when everything is done.

Let's hope another user will indicate you a way to fully automate the process without you clicking anywhere :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...