File tree 2 files changed +9
-5
lines changed
2 files changed +9
-5
lines changed Original file line number Diff line number Diff line change 7
7
"time"
8
8
9
9
"github.com/anaskhan96/soup"
10
+ log "github.com/sirupsen/logrus"
10
11
)
11
12
12
13
func parseProduct (result soup.Root ) {
@@ -17,20 +18,23 @@ func parseProduct(result soup.Root) {
17
18
product .Image = result .Find ("img" , "class" , "s-access-image" ).Attrs ()["src" ]
18
19
product .Price = result .Find ("span" , "class" , "s-price" ).Text ()
19
20
20
- product .GetReviews ()
21
+ if string ([]rune (product .Link )[0 ]) != "/" {
22
+ product .GetReviews ()
23
+ }
21
24
22
25
json .NewEncoder (os .Stdout ).Encode (product )
23
26
}
24
27
25
28
func main () {
26
29
now := time .Now ().UTC ()
27
30
28
- resp , err := soup .Get ("https://www.amazon.in/b/?_encoding =UTF8&node=1389401031&ref_=sv_top_elec_mega_1 " )
31
+ resp , err := soup .Get ("https://www.amazon.in/TVs/b/ref=nav_shopall_sbc_tvelec_television?ie =UTF8&node=1389396031 " )
29
32
30
33
// fmt.Println("Main fetch time: ", time.Since(now))
31
34
// now = time.Now().UTC()
32
35
33
36
if err != nil {
37
+ log .Error ("Encountered error: " , err )
34
38
os .Exit (1 )
35
39
}
36
40
Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
- "os"
5
-
6
4
"github.com/anaskhan96/soup"
5
+ log "github.com/sirupsen/logrus"
7
6
)
8
7
9
8
// A Product represents a product on amazon
@@ -24,7 +23,8 @@ func (product *Product) GetReviews() {
24
23
// now = time.Now().UTC()
25
24
26
25
if err != nil {
27
- os .Exit (1 )
26
+ log .Error ("Encountered error {%s} while vising: %#v" , err , product )
27
+ return
28
28
}
29
29
30
30
doc := soup .HTMLParse (resp )
You can’t perform that action at this time.
0 commit comments