Skip to content

Commit 3bddea4

Browse files
authored
Merge pull request #827 from Shinku-Chen/xml-index
add : NewXMLElement add index
2 parents 92a82bd + 2d1cae2 commit 3bddea4

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

colly.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,8 +1272,9 @@ func (c *Collector) handleOnXML(resp *Response) error {
12721272
if !cc.active.Load() {
12731273
continue
12741274
}
1275-
for _, n := range htmlquery.Find(doc, cc.Query) {
1275+
for i, n := range htmlquery.Find(doc, cc.Query) {
12761276
e := NewXMLElementFromHTMLNode(resp, n)
1277+
e.Index = i
12771278
if c.debugger != nil {
12781279
c.debugger.Event(createEvent("xml", resp.Request.ID, c.ID, map[string]string{
12791280
"selector": cc.Query,

xmlelement.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type XMLElement struct {
3737
// based on how the XMLElement was created.
3838
DOM interface{}
3939
isHTML bool
40+
// Index stores the position of the current element within all the elements matched by an OnXML callback
41+
Index int
4042
}
4143

4244
// NewXMLElementFromHTMLNode creates a XMLElement from a html.Node.

0 commit comments

Comments
 (0)