This should work:
Code: Select all
F3::
Xl := ComObjActive("Excel.Application")
WinActivate, % "ahk_id " . Xl.hwnd
XlSht := Xl.ActiveSheet
row := Xl.ActiveCell.Row - 1
col := Xl.ActiveCell.Column
Loop {
url := XlSht.Cells(++row, col).value
if !(url ~= "^https?://") {
MsgBox, Incorrect url
Return
}
try html := GetHtml(url)
catch
continue
if !RegExMatch(html, "id=""websiteurlfecth""[^>]+?value=""\Khttp[^""]+", extractedUrl) {
MsgBox, 4, % " ", Can't extract url. Continue?
IfMsgBox, No
Return
continue
}
XlSht.Cells(row, col + 1).value := extractedUrl
}
Return
GetHtml(url) {
Whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
Whr.Open("GET", url, true)
Whr.Send()
Whr.WaitForResponse()
status := Whr.status
if (status != 200)
throw "HttpRequest error, status: " . status
Arr := Whr.responseBody
pData := NumGet(ComObjValue(arr) + 8 + A_PtrSize)
length := arr.MaxIndex() + 1
Return html := StrGet(pData, length, "UTF-8")
}