I need help please making a autohotkey script that scrapes (I think a javascript)…
- 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
- 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
URLDownloadToFilefunction, 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: " . albumLink1Please replace the "https://example.com" with the URL you want to scrape.
- User
No links :(
- 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" . linksReplace 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.