Skip to content
The Chat Archive
gpt-4-0314· OpenAI WildChat-4.8M (AI2)

I need help please making a autohotkey script that scrapes (I think a javascript)…

  1. User

    I need help please making a autohotkey script that scrapes (I think a javascript) webpage and using regex extract hyperlinks with a base url of /us-en/album/. For example a line in the html could be and I need just between the first two " char. So the following: /us-en/album/no-escape-doctor-p-remix-ganja-white-night-and-dirt-monkey/lxoh1ckw0j04b

  2. Assistant

    Here's a simple AutoHotkey script that will scrape a webpage and extract the hyperlinks with a base url of "/us-en/album/". Please note that this example uses the URLDownloadToFile function, so the source code of the web page will be temporarily saved as an HTML file.

    ; AutoHotkey Script: Scrape Webpage and Extract Hyperlinks
    #NoEnv
    SendMode Input
    SetWorkingDir %A_ScriptDir%
    
    ; Download HTML source code to a temporary file
    url := "https://example.com" ; Replace with the URL you want to scrape
    tempFilePath := A_ScriptDir . "\temp.html"
    URLDownloadToFile, %url%, %tempFilePath%
    
    ; Read the temporary HTML file
    FileRead, htmlSource, %tempFilePath%
    
    ; Extract hyperlinks with base url of "/us-en/album/"
    RegExMatch(htmlSource, "<a href=\x22(us-en/album[^>/]+)", albumLink)
    
    ; Clean up - Delete the temporary file
    FileDelete, %tempFilePath%
    
    ; Display the extracted hyperlink
    MsgBox, % "Extracted link: " . albumLink1
    

    Please replace the "https://example.com" with the URL you want to scrape.

  3. User

    No links :(

  4. Assistant

    I apologize for the mistake. Please use this updated script:

    ; AutoHotkey Script: Scrape Webpage and Extract Hyperlinks
    #NoEnv
    SendMode Input
    SetWorkingDir %A_ScriptDir%
    
    ; Download HTML source code to a temporary file
    url := "https://example.com" ; Replace with the URL you want to scrape
    tempFilePath := A_ScriptDir . "\temp.html"
    URLDownloadToFile, %url%, %tempFilePath%
    
    ; Read the temporary HTML file
    FileRead, htmlSource, %tempFilePath%
    
    ; Extract hyperlinks with base url of "/us-en/album/"
    links :=
    loop
    {
        RegExMatch(htmlSource, "i)<a href=""/(us-en/album[^""]+)", match)
        if (match = "")
            break
        htmlSource := StrReplace(htmlSource, match, "", 1)
        links .= match1 "`n"
    }
    
    ; Clean up - Delete the temporary file
    FileDelete, %tempFilePath%
    
    ; Display the extracted hyperlinks
    MsgBox, % "Extracted links:`n`n" . links
    

    Replace the "https://example.com" with the URL you want to scrape. The script now loops through the HTML source and finds all the links with the base URL of "/us-en/album/". The links will be displayed in a message box.