-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
221 lines (190 loc) · 4.79 KB
/
main.go
File metadata and controls
221 lines (190 loc) · 4.79 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
package main
//make curly braces paranthesis
import (
"fmt"
"net/http"
"os"
"strings"
"github.com/PuerkitoBio/goquery"
)
// this is changes
func dis(url string) ([]string, []string, []string) {
// making a url request
//write err instead of _
resp, err := http.Get(url)
if err != nil {
fmt.Println("fail1")
os.Exit(3)
}
//closing my request
defer resp.Body.Close()
// goquery doc
doc, _ := goquery.NewDocumentFromReader(resp.Body)
// creating array for diseases
var d []string
var l []string
var p []string
var class string
doc.Find(".unstyled-list").Each(func(_ int, s *goquery.Selection) {
s.Find("li").Each(func(_ int, t *goquery.Selection) {
t.Find("a").Each(func(_ int, p *goquery.Selection) {
class, _ = p.Attr("class")
})
// class, _ := t.Attr("class")
if class == "" {
t.Find("a").Each(func(_ int, q *goquery.Selection) {
newURL, _ := q.Attr("href")
h, parv := branchone(newURL)
l = append(l, h...)
p = append(p, parv...)
})
text := t.Text()
text2 := strings.Split(fmt.Sprint(text), "—")
text3 := fmt.Sprint(text2[0])
// fmt.Println(text3)
dis := text3 + "|"
// l = append(l, gog(text3))
d = append(d, dis)
}
})
})
return d, l, p
}
func caller() ([]string, []string, []string) {
a := "b"
link := "https://www.cdc.gov/diseasesconditions/az/" + a + ".html"
d, f, l := dis(link)
return d, f, l
}
//function to further branch and extract data
func branch(url string) []string {
var data []string
resp, err := http.Get(url)
if err != nil {
return data
}
defer resp.Body.Close()
doc, _ := goquery.NewDocumentFromReader(resp.Body)
doc.Find(".syndicate").Each(func(_ int, p *goquery.Selection) {
p.Find(".row").Each(func(_ int, q *goquery.Selection) {
q.Find("ul").Each(func(_ int, g *goquery.Selection) {
_, c := g.Attr("class")
if c == true {
g.SetText("")
}
})
q.Find("h4").Each(func(_ int, f *goquery.Selection) {
f.SetText("")
})
q.Find("h3").Each(func(_ int, r *goquery.Selection) {
str := "--" + r.Text()
r.SetText(str)
})
q.Find(".card-header").Each(func(_ int, s *goquery.Selection) {
s.SetText("")
})
data = append(data, strings.TrimSpace(fmt.Sprint(q.Text())))
})
})
return data
}
func branchone(url string) ([]string, []string) {
var re []string
var links []string
resp, err := http.Get(url)
if err != nil {
fmt.Println("fail3")
os.Exit(3)
}
defer resp.Body.Close()
doc, _ := goquery.NewDocumentFromReader(resp.Body)
doc.Find(".syndicate").Each(func(_ int, p *goquery.Selection) {
p.Find(".row").Each(func(_ int, q *goquery.Selection) {
q.Find("ul").Each(func(_ int, g *goquery.Selection) {
_, c := g.Attr("class")
if c == true {
g.SetText("")
}
})
q.Find("h4").Each(func(_ int, f *goquery.Selection) {
f.SetText("")
})
q.Find("h3").Each(func(_ int, r *goquery.Selection) {
str := "--" + r.Text()
r.SetText(str)
})
q.Find(".col-md-4").Each(func(_ int, np *goquery.Selection) {
np.Find("a").Each(func(_ int, nwr *goquery.Selection) {
attr, _ := nwr.Attr("href")
// j := branch(attr)
links = append(links, attr)
nwr.SetText("")
})
})
q.Find(".card-header").Each(func(_ int, s *goquery.Selection) {
s.SetText("")
})
q.Find(".card-title").Each(func(_ int, sp *goquery.Selection) {
sp.SetText("")
})
q.Find(".card-body").Each(func(_ int, n *goquery.Selection) {
n.SetText("")
})
q.Find(".card").Each(func(_ int, gq *goquery.Selection) {
gq.SetText("")
})
q.Find(".text-right").Each(func(_ int, nf *goquery.Selection) {
nf.SetText("")
})
yy := strings.TrimSpace(fmt.Sprint(q.Text()))
re = append(re, yy)
})
})
return re, links
}
//function for google query
// func gog(name string) string {
// newname := strings.Split(name, " ")
// url := "http://www.google.com/search?q=symptoms+of+"
// for i := 0; i < len(newname); i++ {
// url = url + newname[i] + "+"
// }
// fmt.Println(url)
// resp, err := http.Get(url)
// if err != nil {
// os.Exit(3)
// }
// // fmt.Println(resp)
// //closing the request
// defer resp.Body.Close()
// //goquery doc
// doc, _ := goquery.NewDocumentFromReader(resp.Body)
// fmt.Println(doc)
// //creating array for symptoms
// var symp []string
// doc.Find(".col").Each(func(_ int, p *goquery.Selection) {
// fmt.Println("found a col")
// symp = append(symp, p.Text())
// })
// s := fmt.Sprint(symp)
// return s
// }
func newfunc(t []string) []string {
var a []string
for i := 0; i < len(t); i++ {
h := branch(t[i])
a = append(a, h...)
}
return a
}
func main() {
a, b, c := caller()
d := newfunc(c)
fmt.Println(a)
fmt.Println(b)
fmt.Println(d)
fmt.println("hello")
fmt.println("hello world parv noob")
fmt.println("lets goo")
fmt.println("hello")
}