ComObject("HTMLfile") for extracting HTML Source from clipboard Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
User avatar
JoeSchmoe
Posts: 129
Joined: 08 Dec 2014, 08:58

Re: ComObject("HTMLfile") for extracting HTML Source from clipboard

Post by JoeSchmoe » 03 Apr 2023, 14:11

Thanks! Seemed to work fine beforehand anyway due to the null termination.

User avatar
FanaticGuru
Posts: 1908
Joined: 30 Sep 2013, 22:25

Re: ComObject("HTMLfile") for extracting HTML Source from clipboard

Post by FanaticGuru » 03 Apr 2023, 14:51

teadrinker wrote:
03 Apr 2023, 14:02
Yep, in AHK v1 StrPut() returns the size in characters, not bytes, hence the confusion.

That is really good to know. I pondered for quite a bit if it was supposed to be "* 2" or "* 2 + 8".

I am still learning and not confident on getting everything just right with DllCall, StrPut, offsets, buffers, etc. In the future that will be one less thing to worry about.

FG
Hotkey Help - Help Dialog for Currently Running AHK Scripts
AHK Startup - Consolidate Multiply AHK Scripts with one Tray Icon
Hotstring Manager - Create and Manage Hotstrings
[Class] WinHook - Create Window Shell Hooks and Window Event Hooks

teadrinker
Posts: 4400
Joined: 29 Mar 2015, 09:41
Contact:

Re: ComObject("HTMLfile") for extracting HTML Source from clipboard

Post by teadrinker » 03 Apr 2023, 15:13

FanaticGuru wrote: I am still learning
Anyone who is involved in programming "is still learning". :)

jkeks
Posts: 60
Joined: 20 Oct 2019, 00:24
Contact:

Re: ComObject("HTMLfile") for extracting HTML Source from clipboard

Post by jkeks » 22 Sep 2023, 04:06

teadrinker wrote:
19 Mar 2023, 12:25
JoeSchmoe wrote: @chatGPT
Don't use chatGPT for AHK, it doesn't make sense. Perhaps you need this:

Code: Select all

F11:: {
    if CopySelectedText() {
        if html := ExtractHtmlData()
            url := RegExReplace(html, 's)(?<=href=")[^"]+(*SKIP)(*F)|.')
        MsgBox 'text: ' . A_Clipboard . '`nurl: ' . url
    }

    CopySelectedText() {
        ClipSaved := ClipboardAll()
        A_Clipboard := ''
        Send '^c'
        ClipWait 1
        if (A_Clipboard = '') {
            A_Clipboard := ClipSaved
            MsgBox 'Failed to copy data'
            return
        }
        return true
    }

    ExtractHtmlData() {
        static CF_HTML := DllCall('RegisterClipboardFormat', 'Str', 'HTML Format')
        DllCall('OpenClipboard', 'Ptr', A_ScriptHwnd)
        format := 0
        Loop {
            format := DllCall('EnumClipboardFormats', 'UInt', format)
        } until format = CF_HTML || format = 0
        if format != CF_HTML {
            DllCall('CloseClipboard')
            return
        }
        hData := DllCall('GetClipboardData', 'UInt', CF_HTML, 'Ptr')
        pData := DllCall('GlobalLock', 'Ptr', hData, 'Ptr')
        html := StrGet(pData, 'UTF-8')
        DllCall('GlobalUnlock', 'Ptr', hData)
        DllCall('CloseClipboard')
        return html
    }
}
Thank you for ExtractHtmlData() function )))

Post Reply

Return to “Ask for Help (v2)”