-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathGetNestedTag.ahk
36 lines (32 loc) · 1.14 KB
/
GetNestedTag.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
Function : GetNestedTag() v1
Author : hi5
Doc + Examples : https://github.com/hi5/GetNestedTag/
AHK Forum : http://www.autohotkey.com/forum/viewtopic.php?t=77653
AutoHotkey : Basic 1.0.48.05, AutoHotkey_L 1.0.X series
Purpose : Function (parser) to retrieve the contents of a (nested) HTML-tag
*/
GetNestedTag(data,tag,occurrence="1")
{
Start:=InStr(data,tag,false,1,occurrence)
RegExMatch(tag,"i)<([a-z]*)",basetag) ; get yer basetag1 here
Loop
{
Until:=InStr(data, "</" basetag1 ">", false, Start, A_Index) + StrLen(basetag1) + 3
Strng:=SubStr(data, Start, Until - Start)
StringReplace, strng, strng, <%basetag1%, <%basetag1%, UseErrorLevel ; start counting to make match
OpenCount:=ErrorLevel
StringReplace, strng, strng, </%basetag1%, </%basetag1%, UseErrorLevel
CloseCount:=ErrorLevel
If (OpenCount = CloseCount)
Break
If (A_Index > 250) ; for safety so it won't get stuck in an endless loop,
{ ; it is unlikely to have over 250 nested tags
strng=
Break
}
}
If (StrLen(strng) < StrLen(tag)) ; something went wrong/can't find it
strng=
Return strng
}