示例#1
0
文件: aturls.go 项目: rose312/mzr
func main() {
	/*
		p, err := helper.GetPage("http://www.8mei.cc")
		fmt.Println("P>>>>>>>>>>>", p, err)
	*/
	//model.AtLinksPostImagesOnTopic(p)
	values := []string{}
	links, _ := helper.AtPages(p)
	for k, v := range links {
		fmt.Println("link #", k)
		content, _ := helper.GetPage(v)
		imgs, n := helper.GetImages(content)

		if n > 0 {
			for k, vv := range imgs {
				//vv为单图url 相对路径的处理较为复杂,这里暂时抛弃相对路径的图片 后续再修正
				if strings.HasPrefix(vv, "/") {
					vv = v + vv[1:]
				}
				fmt.Println("image #", k)
				if !helper.ContainsSets(values, vv) {
					values = append(values, vv)
				}
			}
		}
	}
	fmt.Println("values:", values)

}
示例#2
0
文件: dr.go 项目: rose312/mzr
func GetImagesFromUrl(url string) (urls []string) {

	//c, _ := helper.GetPage(url)
	x, _ := goquery.NewDocumentFromReader(strings.NewReader(`<a href="sfdsfd"></a>`))
	s := x.First()
	for {
		v, b := s.Attr("href")
		fmt.Println(v, b)
		if b == true {
			if !helper.ContainsSets(urls, v) {
				urls = append(urls, v)
			}
		}

		s = s.Next()
		if _, b := s.Attr("href"); b == false {
			break
		}
	}
	return urls
}