如何将 url 源 html 下载到 autohotkey v2 中的字符串

问题描述 投票:0回答:1

我是新来的,希望我能以正确的方式做事!

我想 dl 这个 URL,我以前做过(在帮助下),但现在我不小心删除了我的源,我不记得在哪里得到了帮助或答案是什么,愚蠢的我。 因为我得到的只是状态 406(不可接受)

我使用了 AHK 帮助中的示例,但做了一点修改,添加了 2 行,据我记得有关 SetRequestHeader 的内容

这是帮助中的示例,url已修改


    req := ComObject("Msxml2.XMLHTTP")
    ; Open a request with async enabled.
    req.open("GET", "https://xhamsterlive.com/Lily_Young/profile", true)
    ; Set our callback function.
    req.onreadystatechange := Ready
    ; Send the request.  Ready() will be called when it's complete.
    req.send()
    /*
    ; If you're going to wait, there's no need for onreadystatechange.
    ; Setting async=true and waiting like this allows the script to remain
    ; responsive while the download is taking place, whereas async=false
    ; will make the script unresponsive.
    while req.readyState != 4
        sleep 100
    */
    Persistent

    Ready() {
        if (req.readyState != 4)  ; Not done yet.
            return
        if (req.status == 200) ; OK.
            MsgBox "Text: " req.responseText
        else
            MsgBox "Status " req.status,, 16
        ExitApp
    }

autohotkey http-get sendasynchronousrequest
1个回答
0
投票

巴德知道答案,只需以正确的方式提问即可。

req.setRequestHeader('User-Agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.0.0 Safari/537.36')
req.setRequestHeader('Accept', 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
© www.soinside.com 2019 - 2024. All rights reserved.