@@ -31,6 +31,14 @@ func initDocument(resp string) *goquery.Document {
3131 return doc
3232}
3333
34+ /*
35+ lua:
36+ url = "https://www.bing.com"
37+ timeout = 10
38+ headers = { ["User-Agent"] ="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"}
39+ resp = vmrGetResponse(url, timeout, headers)
40+ selection = vmrInitSelection(resp, "li")
41+ */
3442func InitSelection (L * lua.LState ) int {
3543 resp := L .ToUserData (1 )
3644 if resp == nil {
@@ -47,6 +55,15 @@ func InitSelection(L *lua.LState) int {
4755 return 1
4856}
4957
58+ /*
59+ lua:
60+ url = "https://www.bing.com"
61+ timeout = 10
62+ headers = { ["User-Agent"] ="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"}
63+ resp = vmrGetResponse(url, timeout, headers)
64+ selection = vmrInitSelection(resp, "li")
65+ selection = vmrFind(selection, "a")
66+ */
5067func Find (L * lua.LState ) int {
5168 s := checkSelection (L )
5269 if s == nil {
@@ -59,6 +76,15 @@ func Find(L *lua.LState) int {
5976 return 1
6077}
6178
79+ /*
80+ lua:
81+ url = "https://www.bing.com"
82+ timeout = 10
83+ headers = { ["User-Agent"] ="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"}
84+ resp = vmrGetResponse(url, timeout, headers)
85+ selection = vmrInitSelection(resp, "li")
86+ selection = vmrEq(selection, 0)
87+ */
6288func Eq (L * lua.LState ) int {
6389 s := checkSelection (L )
6490 if s == nil {
@@ -71,18 +97,36 @@ func Eq(L *lua.LState) int {
7197 return 1
7298}
7399
100+ /*
101+ lua:
102+ url = "https://www.bing.com"
103+ timeout = 10
104+ headers = { ["User-Agent"] ="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"}
105+ resp = vmrGetResponse(url, timeout, headers)
106+ selection = vmrInitSelection(resp, "a")
107+ string = vmrAttr(selection, "href")
108+ */
74109func Attr (L * lua.LState ) int {
75110 s := checkSelection (L )
76111 if s == nil {
77- prepareResult ( L , nil )
78- return 0
112+ L . Push ( lua . LString ( "" ) )
113+ return 1
79114 }
80115 attrName := L .ToString (2 )
81116 value := s .AttrOr (attrName , "" )
82117 L .Push (lua .LString (value ))
83118 return 1
84119}
85120
121+ /*
122+ lua:
123+ url = "https://www.bing.com"
124+ timeout = 10
125+ headers = { ["User-Agent"] ="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"}
126+ resp = vmrGetResponse(url, timeout, headers)
127+ selection = vmrInitSelection(resp, "a")
128+ string = vmrText(selection)
129+ */
86130func Text (L * lua.LState ) int {
87131 s := checkSelection (L )
88132 if s == nil {
@@ -94,6 +138,22 @@ func Text(L *lua.LState) int {
94138 return 1
95139}
96140
141+ /*
142+ lua:
143+ url = "https://www.bing.com"
144+ timeout = 10
145+ headers = { ["User-Agent"] ="Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"}
146+ resp = vmrGetResponse(url, timeout, headers)
147+ s = initSelection(resp, "li")
148+ function parseLiItem(i, ss)
149+
150+ local node = vmrFind(ss, "a")
151+ local href = vmrAttr(node, "href")
152+ print(href)
153+
154+ end
155+ vmrEach(s, parseLiItem)
156+ */
97157func Each (L * lua.LState ) int {
98158 s := checkSelection (L )
99159 if s == nil {
0 commit comments