File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -60,15 +60,15 @@ list := htmlquery.Find(doc, "//a")
60
60
#### Find all A elements that have ` href ` attribute.
61
61
62
62
``` go
63
- list := range htmlquery.Find (doc, " //a[@href]" )
63
+ list := htmlquery.Find (doc, " //a[@href]" )
64
64
```
65
65
66
66
#### Find all A elements with ` href ` attribute and only return ` href ` value.
67
67
68
68
``` go
69
- list := range htmlquery.Find (doc, " //a/@href" )
69
+ list := htmlquery.Find (doc, " //a/@href" )
70
70
for _ , n := range list{
71
- fmt.Println (htmlquery.InnerText (n )) // output @href value without A element.
71
+ fmt.Println (htmlquery.SelectAttr (n, " href " )) // output @href value
72
72
}
73
73
```
74
74
@@ -78,6 +78,13 @@ for _ , n := range list{
78
78
a := htmlquery.FindOne (doc, " //a[3]" )
79
79
```
80
80
81
+ ### Find children element (img) under A ` href ` and print the source
82
+ ``` go
83
+ a := htmlquery.FindOne (doc, " //a" )
84
+ img := htmlquery.FindOne (a, " //img" )
85
+ fmt.Prinln (htmlquery.SelectAttr (img, " src" )) // output @src value
86
+ ```
87
+
81
88
#### Evaluate the number of all IMG element.
82
89
83
90
``` go
You can’t perform that action at this time.
0 commit comments