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


Golang Document.Text方法代碼示例

本文整理匯總了Golang中github.com/PuerkitoBio/goquery.Document.Text方法的典型用法代碼示例。如果您正苦於以下問題:Golang Document.Text方法的具體用法?Golang Document.Text怎麽用?Golang Document.Text使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/PuerkitoBio/goquery.Document的用法示例。


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

示例1: GetStudent

func GetStudent(d *goquery.Document, rollno int) (s Student, ok bool) {
	//sanity on document
	// if v := d.Find(".titlehead").Children().Text(); v != "JEE (Advanced) - 2013 Result" {
	// 	return Student{}, false
	// }
	dtext := strings.Trim(d.Text(), " ")
	dfields := strings.Fields(dtext)
	for _, v := range dfields {
		s.Plaintext += v + " "
	}
	s.Plaintext = strings.Trim(s.Plaintext, " ")
	if isInvalid(dtext) {
		return s, false
	}
	ok = true
	s.Rollno = rollno
	s.Region = s.Rollno / 10000
	if !isSelected(dtext) {
		return
	}
	s.Selected = true
	s.Rank, _ = strconv.Atoi(d.Find(".style7").First().Text())
	text, _ := d.Find(".titlehead").First().Parent().Next().Children().Children().First().Html()
	tokens := strings.Split(text, "<br/>")
	nameToks := strings.Fields(tokens[1])
	nameToks = nameToks[2:len(nameToks)]
	for _, v := range nameToks {
		s.Name += v + " "
	}
	s.Name = strings.Trim(s.Name, " ")
	s.Q = GetQuota(dtext)
	return
}
開發者ID:korroktheslavemaster,項目名稱:jee,代碼行數:33,代碼來源:parser.go

示例2: markTopImage

func markTopImage(d *goquery.Document) bool {
	changed := false

	totalTextCount := len(d.Text())
	img := d.Find("img")

	if img.Length() == 0 {
		return changed
	}

	if totalTextCount == 0 {
		img.AddClass("top-image")
		changed = true
	} else {
		afterTextCount := len(img.NextAll().Text())
		// Add any text-node siblings of the image
		for n := img.Get(0).NextSibling; n != nil; n = n.NextSibling {
			if n.Type == html.TextNode {
				afterTextCount += len(n.Data)
			}
		}

		img.Parents().Each(func(i int, s *goquery.Selection) {
			afterTextCount += len(s.NextAll().Text())
		})

		if totalTextCount-afterTextCount <= afterTextCount {
			img.AddClass("top-image")
			changed = true
		}
	}

	return changed
}
開發者ID:urandom,項目名稱:readeef,代碼行數:34,代碼來源:top_image_marker.go

示例3: parseStatusPage

func parseStatusPage(s *goquery.Document) (*Status, error) {
	c := s.Find(".container").First()
	t := c.Find("div").First().Text()
	if t != ">証拠金狀況照會<" {
		return nil, fmt.Errorf("cannot open \"証拠金狀況照會\", but %#v", t)
	}

	results := []string{}
	c.Find("hr").First().NextUntil("hr").Each(
		func(_ int, s *goquery.Selection) {
			results = append(results, s.Text())
		})

	orig := map[string]string{}
	for i := 0; i+1 < len(results); i += 2 {
		k := strings.TrimSpace(strings.Replace(results[i], ":", "", -1))
		v := strings.TrimSpace(results[i+1])
		orig[k] = v
	}

	return &Status{
		ActualDeposit:    parsePrice(orig["有効証拠金額"]),
		NecessaryDeposit: parsePrice(orig["必要証拠金額"]),
	}, nil
}
開發者ID:imos,項目名稱:fxtools,代碼行數:25,代碼來源:status.go

示例4: parsePositionDetailsPage

func parsePositionDetailsPage(s *goquery.Document) (*Position, error) {
	c := s.Find(".container").First()
	t := c.Find("div").First().Text()
	if t != ">ポジション情報(詳細)<" {
		return nil, fmt.Errorf("cannot open \"ポジション情報(詳細)\", but %#v", t)
	}

	position := &Position{}

	// タイトル行の削除
	c.Find("hr").First().Next().PrevAll().Remove()

	// 通貨名の設定
	position.Currency = c.Find("div").First().Text()
	// 通貨名行の削除
	c.Find("hr").First().Next().PrevAll().Remove()

	// メニューの削除
	c.Find("hr").First().Prev().NextAll().Remove()

	results := []string{}
	c.Find("div").Each(func(_ int, s *goquery.Selection) {
		results = append(results, s.Text())
	})

	orig := map[string]string{}
	for i := 0; i+1 < len(results); i += 2 {
		k := strings.TrimSpace(strings.Replace(results[i], ":", "", -1))
		v := strings.TrimSpace(results[i+1])
		orig[k] = v
	}

	position.PositionId = orig["ポジション番號"]
	position.TransactionTime = orig["約定日時"]
	if orig["売買"] == "売" {
		position.Side = "sell"
	} else if orig["売買"] == "買" {
		position.Side = "buy"
	}
	rate, err := strconv.ParseFloat(orig["約定価格"], 64)
	if err != nil {
		return nil, fmt.Errorf("invalid transaction rate: %v", err)
	}
	position.TransactionRate = rate
	lot, err := strconv.ParseInt(orig["殘Lot數"], 10, 64)
	position.Amount = lot * 1000
	return position, nil
}
開發者ID:imos,項目名稱:fxtools,代碼行數:48,代碼來源:position.go

示例5: findProductsOnSearchPage

func findProductsOnSearchPage(doc *goquery.Document, c chan<- *products.ProductUrls) int {
	if strings.Contains(doc.Text(), "Robot Check") {
		fmt.Println("We're being blocked by captcha :(")
		os.Exit(2)
	}

	numberOfProductsFound := 0
	doc.Find(".s-access-image").Each(func(i int, image *goquery.Selection) {
		product, error := extractProduct(image)
		if error == nil {
			numberOfProductsFound++
			c <- &product
		} else {
			log.Printf("Unable to extract product from goquery selection: %v\n", error)
		}
	})

	return numberOfProductsFound
}
開發者ID:eriklarko,項目名稱:purple-shopper,代碼行數:19,代碼來源:product-finder.go

示例6: parseOrderDetailsPage

func parseOrderDetailsPage(s *goquery.Document) (*Order, error) {
	c := s.Find(".container").First()
	t := c.Find("div").First().Text()
	if t != ">注文情報(詳細)<" {
		return nil, fmt.Errorf("cannot open \"注文情報(詳細)\", but %#v", t)
	}

	o := &Order{}
	// タイトル行の削除
	c.Find("hr").First().Next().PrevAll().Remove()

	c.Find("a").Each(func(_ int, s *goquery.Selection) {
		href, _ := s.Attr("href")
		// 取消リンク
		if strings.HasPrefix(href, "../otc/CT01.html?") {
			u, err := url.Parse(href)
			if err != nil || u.RawQuery == "" {
				return
			}
			v, err := url.ParseQuery(u.RawQuery)
			if err != nil {
				return
			}
			o.OrderId = v.Get("order_id")
			o.OrderMethod = v.Get("order_method")
		}
		// 指定決済リンク
		if strings.HasPrefix(href, "../common/I124.html?") {
			u, err := url.Parse(href)
			if err != nil || u.RawQuery == "" {
				return
			}
			v, err := url.ParseQuery(u.RawQuery)
			if err != nil {
				return
			}
			o.PositionId = v.Get("position_id")
		}
	})

	// メニューの削除
	c.Find("hr").First().Prev().NextAll().Remove()

	results := []string{}
	c.Find("div").Each(func(_ int, s *goquery.Selection) {
		results = append(results, s.Text())
	})

	orig := map[string]string{}
	for i := 0; i+1 < len(results); i += 2 {
		k := strings.TrimSpace(strings.Replace(results[i], ":", "", -1))
		v := strings.TrimSpace(results[i+1])
		orig[k] = v
	}

	o.Currency = orig["通貨ペア"]
	lot, err := strconv.ParseInt(orig["注文Lot數"], 10, 64)
	if err != nil {
		return nil, err
	}
	o.Amount = lot * 1000
	if orig["売買"] == "売" {
		o.Side = "sell"
	} else if orig["売買"] == "買" {
		o.Side = "buy"
	} else {
		return nil, fmt.Errorf("invalid value for 売買: %#v", orig["売買"])
	}
	if orig["執行條件"] == "指値" {
		o.IsStop = false
	} else if orig["執行條件"] == "逆指" {
		o.IsStop = true
	} else {
		return nil, fmt.Errorf("invalid value for 執行條件: %#v", orig["執行條件"])
	}
	o.Price, err = strconv.ParseFloat(orig["指定レート"], 64)
	if err != nil {
		return nil, err
	}
	if orig["注文區分"] == "指定決済" {
		o.IsSettlement = true
	} else if orig["注文區分"] == "売買" {
		o.IsSettlement = false
	} else {
		return nil, fmt.Errorf("invalid value for 注文區分: %#v", orig["注文區分"])
	}

	return o, nil
}
開發者ID:imos,項目名稱:fxtools,代碼行數:89,代碼來源:order.go


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