mirror of
https://github.com/LeRoid-hub/Mensa-API.git
synced 2025-01-31 11:44:55 +00:00
29 lines
442 B
Go
29 lines
442 B
Go
|
package scrape
|
||
|
|
||
|
import (
|
||
|
"io"
|
||
|
"strings"
|
||
|
|
||
|
"github.com/PuerkitoBio/goquery"
|
||
|
)
|
||
|
|
||
|
func ScrapeState(h io.ReadCloser) []string {
|
||
|
var cities []string
|
||
|
|
||
|
doc, err := goquery.NewDocumentFromReader(h)
|
||
|
if err != nil {
|
||
|
return []string{}
|
||
|
}
|
||
|
|
||
|
doc.Find("a.primary").Each(func(i int, s *goquery.Selection) {
|
||
|
href, _ := s.Attr("href")
|
||
|
print(href)
|
||
|
|
||
|
city := strings.Split(href, "/")[0]
|
||
|
|
||
|
cities = append(cities, string(city))
|
||
|
})
|
||
|
return cities
|
||
|
|
||
|
}
|