當前位置: 首頁>>代碼示例>>Golang>>正文


Golang goquery.ParseUrl函數代碼示例

本文整理匯總了Golang中github.com/opesun/goquery.ParseUrl函數的典型用法代碼示例。如果您正苦於以下問題:Golang ParseUrl函數的具體用法?Golang ParseUrl怎麽用?Golang ParseUrl使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ParseUrl函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: main

func main() {
	var url = "http://toutiao.io"

	p, err := goquery.ParseUrl(url)

	if err != nil {
		panic(err)
	}
	// toutiao.io
	title := p.Find("title").Text()

	fmt.Println(title)

	t := p.Find(".title a")
	for i := 0; i < t.Length(); i++ {
		d := t.Eq(i).Text()
		l := t.Eq(i).Attr("href")
		c := p.Find(".summary a").Eq(i).Text()
		fmt.Println(l, d, "||", c)
	}

	// geek.csdn.net
	p, err = goquery.ParseUrl("http://geek.csdn.net/hotest")
	if err != nil {
		panic(err)
	}

	title = p.Find("title").Text()
	t = p.Find("a.title")

	fmt.Println(title)
	for i := 0; i < t.Length(); i++ {
		l := t.Eq(i).Attr("href")
		c := t.Eq(i).Text()
		fmt.Println(l, c)
	}
	// ituring.com
	p, err = goquery.ParseUrl("http://www.ituring.com.cn/")
	if err != nil {
		panic(err)
	}

	title = p.Find("title").Text()
	t = p.Find(".arc-list").Eq(0)
	x, _ := goquery.ParseString(t.Html())

	t = x.Find("dt a")

	fmt.Println(title)

	for i := 0; i < t.Length(); i++ {
		c := t.Eq(i).Text()
		l := t.Eq(i).Attr("href")
		fmt.Printf("http://www.ituring.com.cn/%s %s\n", l, c)
	}
}
開發者ID:click1,項目名稱:daily-code,代碼行數:56,代碼來源:fetch-toutiao.go

示例2: GetDownloadLinks

func GetDownloadLinks(url string) {
	/*
	 *通過傳入的書籍URL地址;提取到下載地址
	 *提取書籍的名稱和url地址
	 *
	 */
	fmt.Println("\n")
	fmt.Println("書籍地址", url)
	r, err := goquery.ParseUrl(url)
	if err != nil {
		panic(err)
	} else {
		text := r.Find(".download-link")
		bookName := r.Find("h1").Text()
		fmt.Println("書籍名稱:", bookName)
		//fmt.Println(text)
		for i := 0; i < text.Length(); i++ {
			downloadlink := text.Eq(i).Attr("href")
			fmt.Println("下載地址", downloadlink)
			DownloadBook(downloadlink, bookName)
		}

	}

}
開發者ID:zhuyouzha,項目名稱:EbookDownloadTools,代碼行數:25,代碼來源:EbookDownloadTools.go

示例3: ParsePanMap

func ParsePanMap(date string, history bool) {
	bet_url := strings.Replace(myinit.DateUrl, "TTT", date, -1)
	fmt.Println("bet_url:", bet_url)

	pan_url := myinit.PanUrl

	html_obj, _ := goquery.ParseUrl(bet_url)

	schedule_trs := html_obj.Find(".bet_table tbody tr")
	for i, _ := range schedule_trs {
		schedule_int_info := make(map[string]int)
		schedule_string_info := make(map[string]string)

		// insert schedule
		fid, _ := strconv.Atoi(schedule_trs.Eq(i).Attr("fid"))
		schedule_int_info["schedule_fenxi_id"] = int(fid)
		schedule_string_info["schedule_home"] = common.ConvToGB(schedule_trs.Eq(i).Attr("homesxname"))
		schedule_string_info["schedule_guest"] = common.ConvToGB(schedule_trs.Eq(i).Attr("awaysxname"))
		schedule_string_info["schedule_date"] = schedule_trs.Eq(i).Attr("pdate")

		schedule_pan_url := strings.Replace(pan_url, "TTT", strconv.Itoa(fid), -1)

		GetPanValue(schedule_pan_url, fid, schedule_string_info, date)

	}
}
開發者ID:ryancsq,項目名稱:test,代碼行數:26,代碼來源:schedule.go

示例4: checkPanUseable

func checkPanUseable(schedule_pan_url string, schedule_fenxi_id int, schedule_string_info map[string]string, date string) (res bool) {
	pan_html_obj, _ := goquery.ParseUrl(schedule_pan_url)

	odds_tr := pan_html_obj.Find(".table_cont table tbody tr")

	if odds_tr.Length() == 0 {
		return false
	}
	for i := 0; i < odds_tr.Length(); i++ {
		tr_item := odds_tr.Eq(i)
		td_of_company := tr_item.Find("td").Eq(1)
		if td_of_company.Find("p a").Attr("title") == "" {
			continue
		}

		is_useable := checkPanTr(tr_item, schedule_fenxi_id)
		if is_useable == false {
			return false
		}
	}
	if odds_tr.Length() >= 30 {
		ajax_res := checkPanUseableFromAjax(30, schedule_fenxi_id)
		if ajax_res == false {
			return false
		}
	}
	return true
}
開發者ID:ryancsq,項目名稱:test,代碼行數:28,代碼來源:pan.go

示例5: ParseBetUrl

func ParseBetUrl(date string, history bool) {
	bet_url := getBetUrl(date)
	html_obj, _ := goquery.ParseUrl(bet_url)
	schedule_trs := html_obj.Find(".bet_table tbody tr")
	for i, _ := range schedule_trs {
		is_end := schedule_trs.Eq(i).Attr("isend")
		if is_end == "1" && history == false {
			continue
		}

		today := common.GetToday()
		schedule_is_today := today == schedule_trs.Eq(i).Attr("pdate")
		//		fmt.Println("schedule_is_today:===",schedule_is_today)
		if schedule_is_today == false && history == false {
			//			continue
		}

		schedule_int_info, schedule_string_info := pareseScheduleTR(schedule_trs.Eq(i))
		schedule.Add(schedule_int_info, schedule_string_info)
		// end insert schedule

		//parse pan data
		res := ParsePanByScheduleFenxiId(schedule_int_info["schedule_fenxi_id"], date, schedule_string_info)
		if res == false {
			continue
		}
		//計算預測比率
		calcScheduleResult(schedule_int_info, schedule_string_info)
		//				return

	}
}
開發者ID:ryancsq,項目名稱:test,代碼行數:32,代碼來源:schedule.go

示例6: GetZhihuQuestionList

func GetZhihuQuestionList(url string) {
	/*
	 *  通過傳入的url、分析提取url裏麵的問題列表
	 *  用for循環提交分頁URL地址
	 *  並用goquery查找頁麵內容是否存在、用以判斷是否還有分頁
	 *  用提取到的短URL加上統一URL地址頭得到某一個完整URL地址
	 */
	urlHeader := "http://www.zhihu.com"
	for i := 1; i < 100; i++ {
		url := url + strconv.Itoa(i)
		fmt.Println(url)
		r, err := goquery.ParseUrl(url)
		if err != nil {
			panic(err)
		} else {
			text := r.Find(".zm-item-title a") //查找所有問題列表
			if text.Length() > 0 {
				//取到text裏麵的所有"href"屬性的數據
				for i := 0; i < text.Length(); i++ {
					singleUrl := urlHeader + text.Eq(i).Attr("href")
					urlList = append(urlList, singleUrl)
					GetSubjectBody(singleUrl)
				}
			} else { //如果text的長度小於0表示沒有找到
				fmt.Print(".........沒有文章了.......\n")
				break
			}
		}
	}

}
開發者ID:huaisha1224,項目名稱:ZhihuToNote,代碼行數:31,代碼來源:ZhihuToNote.go

示例7: ParseBetUrl

func ParseBetUrl(date string, history bool) {
	bet_url := getBetUrl(date)
	html_obj, _ := goquery.ParseUrl(bet_url)
	schedule_trs := html_obj.Find(".bet_table tbody tr")
	for i, _ := range schedule_trs {
		is_end := schedule_trs.Eq(i).Attr("isend")
		if is_end == "1" && history == false {
			continue
		}

		schedule_int_info, schedule_string_info := pareseScheduleTR(schedule_trs.Eq(i), date)
		//if(schedule_int_info["schedule_fenxi_id"]!=556793){
		//	continue
		//}
		//parse pan data
		res := ParsePanByScheduleFenxiId(schedule_int_info["schedule_fenxi_id"], date, schedule_string_info)
		if res == false {
			continue
		}
		schedule.Add(schedule_int_info, schedule_string_info)
		//計算預測比率
		calcScheduleResult(schedule_int_info, schedule_string_info)
		//				return

	}
}
開發者ID:ryancsq,項目名稱:test,代碼行數:26,代碼來源:schedule.go

示例8: GetZi5PageUrl

func GetZi5PageUrl(category string) {
	/*
	 *通過傳入的分類標簽;得到分類地址
	 *用For循環傳遞分頁頁碼;然後用goquery得到單個書籍的URL地址;
	 *如果分頁裏麵得不到值就認為分頁結束
	 *
	 *
	 */
	url := "http://book.zi5.me/archives/book-gentre/"
	//var category string
	for i := 1; i < 100; i++ {
		url := url + category + "/page/" + strconv.Itoa(i) //分頁地址
		fmt.Println("\n")
		fmt.Println("分頁地址", i, url)
		r, err := goquery.ParseUrl(url)
		if err != nil {
			panic(err)
		} else {
			//查找<class="thumb-holder" > 和<a
			text := r.Find(".thumb-holder a")
			//fmt.Println(text)
			if text.Length() > 0 {
				//取到text裏麵的所有"href"屬性的數據
				for x := 0; x < text.Length(); x++ {
					bookUrl := text.Eq(x).Attr("href")
					GetDownloadLinks(bookUrl)
				}
			} else { //如果text的長度小於0表示沒有找到
				fmt.Print("本分類下已經沒有書籍\n")
				break
			}
		}
	}
}
開發者ID:zhuyouzha,項目名稱:EbookDownloadTools,代碼行數:34,代碼來源:EbookDownloadTools.go

示例9: main

func main() {
	x, err := goquery.ParseUrl("http://www.youtube.com/watch?v=ob_nh1WMMzU")
	if err != nil {
		panic(err)
	}
	x.Find("#eow-title").Print()
	fmt.Println("---")
	x, err = goquery.ParseUrl("http://thepiratebay.se/search/one%20day%202011/0/99/0")
	if err != nil {
		panic(err)
	}
	x.Find("a.detLink").Print()
	fmt.Println("---")
	for _, v := range x.Find("a.detLink").HtmlAll() {
		fmt.Println(v)
	}
}
開發者ID:huaisha1224,項目名稱:goquery,代碼行數:17,代碼來源:remote.go

示例10: main

func main() {

	pool := mongo.NewDialPool("localhost:27018", 1000)

	var i int = 1
	chs := make([]chan bool, 50)
	hasMore := true
	for ; i <= 50; i++ {
		ch := make(chan bool)

		chs[i-1] = ch

		go func(i int, ch chan bool) {
			conn, _ := pool.Get()
			db := &mongo.Database{conn, "meishi", mongo.DefaultLastErrorCmd}
			coll := db.C("foods")
			data, err := goquery.ParseUrl(targetUrl + strconv.Itoa(i))
			if nil != err {
				log.Fatalln("response fail ,", err)
				ch <- false
				return
			}

			nodes := data.Find("div.lp_result_list")
			size := nodes.Find("li").Length()
			if size <= 0 {
				hasMore = false
			}
			for idx := 0; idx < size; idx++ {
				item := nodes.Find("li").Eq(idx)

				link := item.Find("a")
				href := link.Attr("href")
				name := link.Attr("title")
				img := item.Find("img").Attr("src")
				// log.Println(name, "|", href, "|", img)
				if len(name) > 0 {

					err := coll.Upsert(mongo.M{"name": name}, mongo.M{"name": name, "img_url": img, "link": href})

					// log.Println("insert mongo|", err, "|", href)
					log.Println("err", err, "name:", name, "link:", link, "href:", href, "img", img)
				}
			}
			ch <- true
			log.Println(i)

		}(i, ch)
	}

	for i, val := range chs {
		<-val
		log.Println("end:", i)
	}
}
開發者ID:houzhenggang,項目名稱:weixin-1,代碼行數:55,代碼來源:crawler2.go

示例11: ParseResultUrl

func ParseResultUrl(date string, history bool) (res bool) {
	if date == "" {
		return false
	}
	result_url := strings.Replace(myinit.ResultUrl, "DDD", date, -1)
	fmt.Println(result_url)
	schedule_string_info := make(map[string]string)
	schedule_float_info := make(map[string]float32)

	pan_string_info := make(map[string]string)
	pan_float_info := make(map[string]float32)
	html_obj, _ := goquery.ParseUrl(result_url)
	schedule_trs := html_obj.Find(".ld_table tbody tr")
	for i, _ := range schedule_trs {
		if i == 0 {
			continue
		}
		tr := schedule_trs.Eq(i)
		tds := tr.Find("td")
		schedule_string_info["schedule_result_no"] = common.ConvToGB(tds.Eq(0).Html())

		schedule_string_info["schedule_score"] = common.ConvToGB(tds.Eq(6).Html())
		schedule_string_info["schedule_spf_result"] = common.ConvToGB(tds.Eq(11).Html())
		schedule_float_info["schedule_spf_odd"] = common.ConvToFloat32(tds.Eq(12).Text())
		schedule_string_info["schedule_rqspf_result"] = common.ConvToGB(tds.Eq(8).Html())
		schedule_float_info["schedule_rqspf_odd"] = common.ConvToFloat32(tds.Eq(9).Text())
		schedule_string_info["schedule_zjq_result"] = common.ConvToGB(tds.Eq(14).Html())
		schedule_float_info["schedule_zjq_odd"] = common.ConvToFloat32(tds.Eq(15).Text())
		schedule_string_info["schedule_bqc_result"] = common.ConvToGB(tds.Eq(17).Html())
		schedule_float_info["schedule_bqc_odd"] = common.ConvToFloat32(tds.Eq(18).Text())

		pan_string_info["schedule_result_no"] = schedule_string_info["schedule_result_no"]
		pan_string_info["schedule_score"] = schedule_string_info["schedule_score"]
		pan_string_info["schedule_spf_result"] = schedule_string_info["schedule_spf_result"]
		pan_string_info["schedule_rqspf_result"] = schedule_string_info["schedule_rqspf_result"]
		pan_string_info["schedule_zjq_result"] = schedule_string_info["schedule_zjq_result"]
		pan_string_info["schedule_bqc_result"] = schedule_string_info["schedule_bqc_result"]

		has := schedule.CheckExistsByResultNoAndDate(schedule_string_info["schedule_result_no"], date)
		fmt.Println("has:", has)
		if has == false {
			continue
		}
		schedule.UpdateScheduleResult(date, schedule_float_info, schedule_string_info)
		asiapan.UpdateAsiaPanResult(date, schedule_float_info, pan_string_info)
		asiapanlog.UpdateAsiaPanResult(date, pan_float_info, pan_string_info)

	}
	return true
}
開發者ID:ryancsq,項目名稱:test,代碼行數:50,代碼來源:result.go

示例12: GetSubjectBody

func GetSubjectBody(url string) {
	/*
	 *  通過傳入的單個問題url、分析提取url裏麵的問題標題和內容
	 *  用goquery查找頁麵提取裏麵title作為郵件的subject、用html()作為body
	 *
	 */
	//var url = "http://www.zhihu.com/question/24859069"
	p, error := goquery.ParseUrl(url)
	if error != nil {
		panic(error)
	}
	subject := p.Find("title").Text()
	body := p.Html()
	fmt.Print(subject)
	GetConf(subject, body)
}
開發者ID:huaisha1224,項目名稱:ZhihuToNote,代碼行數:16,代碼來源:ZhihuToNote.go

示例13: main

func main() {

	pool := mongo.NewDialPool("localhost:27018", 1000)

	var i int = 1
	ch := make([]chan bool, 20)
	for ; i <= 20; i++ {
		ch[i-1] = make(chan bool)
		go func(i int, ch chan bool) {
			conn, _ := pool.Get()
			db := &mongo.Database{conn, "meishi", mongo.DefaultLastErrorCmd}
			coll := db.C("foods")
			data, err := goquery.ParseUrl(targetUrl + strconv.Itoa(i))
			if nil != err {
				log.Fatalln("response fail ,", err)
				ch <- false
				return
			}

			nodes := data.Find("#page-" + strconv.Itoa(i))
			size := nodes.Find("div.media").Length()
			for idx := 0; idx < size; idx++ {
				item := nodes.Find("div.media").Eq(idx)
				h2 := item.Find("h2")
				link := h2.Find("a")
				href := link.Attr("href")
				name := link.Attr("title")

				img := item.Find("img").Attr("src")
				// log.Println(name, "|", href, "|", img)
				if len(name) > 0 {
					err := coll.Insert(mongo.M{"name": name, "img_url": img, "link": href})
					log.Println("insert mongo|", err, "|", href)
				}
			}
			ch <- true
			log.Println(i)

		}(i, ch[i-1])
	}

	for i, val := range ch {
		<-val
		log.Println("end:", i)
	}
}
開發者ID:houzhenggang,項目名稱:weixin-1,代碼行數:46,代碼來源:crawler.go

示例14: doParsePanUrl

func doParsePanUrl(schedule_pan_url string, schedule_fenxi_id int, schedule_string_info map[string]string, date string) (res bool) {
	pan_int_info := make(map[string]int)
	pan_float_info := make(map[string]float32)
	pan_string_info := make(map[string]string)

	pan_html_obj, _ := goquery.ParseUrl(schedule_pan_url)

	schedule_item := pan_html_obj.Find(".odds_hd_cont table tbody tr td")
	home_td := schedule_item.Eq(0)
	guest_td := schedule_item.Eq(4)
	center_td := schedule_item.Eq(2)

	pan_int_info["schedule_fenxi_id"] = schedule_fenxi_id
	pan_string_info["schedule_date"] = schedule_string_info["schedule_date"]
	pan_string_info["schedule_no"] = schedule_string_info["schedule_no"]
	pan_string_info["schedule_result_no"] = schedule_string_info["schedule_result_no"]
	pan_string_info["schedule_league"] = schedule_string_info["schedule_league"]

	pan_string_info["schedule_home"] = common.ConvToGB(home_td.Find("ul li a").Text())
	pan_string_info["schedule_guest"] = common.ConvToGB(guest_td.Find("ul li a").Text())
	pan_string_info["schedule_game_desc"] = common.ConvToGB(center_td.Find(".odds_hd_center .odds_hd_ls a").Text())
	pan_string_info["schedule_date_desc"] = common.ConvToGB(center_td.Find(".odds_hd_center .game_time ").Text())

	odds_tr := pan_html_obj.Find(".table_cont table tbody tr")
	for i := 0; i < odds_tr.Length(); i++ {
		tr_item := odds_tr.Eq(i)
		td_of_company := tr_item.Find("td").Eq(1)
		if td_of_company.Find("p a").Attr("title") == "" {
			continue
		}

		parse_res := doParsePanTr(tr_item, schedule_fenxi_id, pan_int_info, pan_float_info, pan_string_info, false)
		if parse_res == false {
			return false
		}
	}
	if odds_tr.Length() >= 30 {
		ajax_res := ParsePanUrlFromAjax(30, schedule_fenxi_id, pan_string_info)
		if ajax_res == false {
			return false
		}
	}

	return true
}
開發者ID:ryancsq,項目名稱:test,代碼行數:45,代碼來源:pan.go

示例15: fetchProductName

// use Goquery to fetch product-name from html
func fetchProductName(url string) {
	p, err := goquery.ParseUrl(url)
	if err != nil {
		panic(err)
	} else {
		pTitle := p.Find("title").Text() // fetch the content of title
		fmt.Println(pTitle)

		productList := p.Find(".product-name")
		priceList := p.Find(".product_price")
		for i := 0; i < productList.Length(); i++ {
			product := productList.Eq(i).Text()
			price := priceList.Eq(i).Text()
			fmt.Println(product + ": " + price)

		}

	}
}
開發者ID:sunyuantao,項目名稱:go-lang,代碼行數:20,代碼來源:webScrapter.go


注:本文中的github.com/opesun/goquery.ParseUrl函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。