-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHtmlProcessor.go
More file actions
57 lines (54 loc) · 1.33 KB
/
Copy pathHtmlProcessor.go
File metadata and controls
57 lines (54 loc) · 1.33 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package iqdbAPI
import (
"encoding/json"
"fmt"
"github.com/PuerkitoBio/goquery"
"log"
"net/http"
"strings"
)
func HtmlProcessor(res *http.Response) string {
// Load the HTML document
doc, err := goquery.NewDocumentFromReader(res.Body)
if err != nil {
log.Fatal(err)
}
var resp = Response{
Success: false,
Results: nil,
}
// Find the review items
doc.Find("#pages.pages div table").Each(func(i int, s *goquery.Selection) {
if i > 0 {
// For each item found, get the title
resultUrl, _ := s.Find(".image a").Attr("href")
resultHead := s.Find("tr th").Text()
resultTitles, _ := s.Find(".image img").Attr("title")
split := strings.Fields(s.Find("tr:nth-child(4) td").Text())
split0 := strings.Split(split[0], "×")
if len(split) <= 1 || len(split0) <= 1 {
return
}
resultHeight := split0[0]
resultWidth := split0[1]
resultCategory := split[1]
resultSimilarity := s.Find("tr:nth-child(5) td").Text()
resp.Results = append(resp.Results, Result{
Head: resultHead,
Url: resultUrl,
Titles: resultTitles,
Height: resultHeight,
Width: resultWidth,
Category: resultCategory,
Similarity: resultSimilarity,
})
}
})
resp.Success = true
respP := &resp
j, err := json.Marshal(respP)
if err != nil {
fmt.Println(err)
}
return string(j)
}