예제 #1
0
func generateHeader(easy *curl.CURL) *curl.CURL {
	easy.Setopt(curl.OPT_VERBOSE, false)
	easy.Setopt(curl.OPT_ENCODING, "Accept-Encoding: gzip, deflate")
	easy.Setopt(curl.OPT_HTTPHEADER, []string{"Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"})
	easy.Setopt(curl.OPT_HTTPHEADER, []string{"Accept-Language:id-ID,id;q=0.8,en-US;q=0.6,en;q=0.4"})
	easy.Setopt(curl.OPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.132 Safari/537.36")

	return easy
}
예제 #2
0
func getData(easy *curl.CURL, url string, ep string) (link string) {
	a := ""
	fmt.Println(url)

	//calback
	fooTest := func(buf []byte, userdata interface{}) bool {

		a = a + string(buf)
		//fmt.Println(a)
		nod, err := html.Parse(strings.NewReader(a))
		check(err)

		doc := goquery.NewDocumentFromNode(nod)

		doc.Find("td").Each(func(i int, s *goquery.Selection) {
			s.Eq(0).Each(func(k int, bb *goquery.Selection) {
				bb.Find("img").Each(func(l int, cc *goquery.Selection) {
					link = cc.AttrOr("src", "12345")
				})
			})
		})

		return true
	}

	// page forward to welcome
	easy.Setopt(curl.OPT_URL, url)
	easy.Setopt(curl.OPT_HTTPGET, true)
	easy.Setopt(curl.OPT_WRITEFUNCTION, fooTest)
	if err := easy.Perform(); err != nil {
		println("ERROR: ", err.Error())
	}
	//fmt.Println("success "+link+" ==\n")

	return link
}