本文整理汇总了Golang中github.com/PuerkitoBio/goquery.Selection.Eq方法的典型用法代码示例。如果您正苦于以下问题:Golang Selection.Eq方法的具体用法?Golang Selection.Eq怎么用?Golang Selection.Eq使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/PuerkitoBio/goquery.Selection
的用法示例。
在下文中一共展示了Selection.Eq方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: findZipcode
func findZipcode(index int, details *goquery.Selection) string {
if details.Length() < index {
return ""
}
zipcode_p := strings.Split(details.Eq(index).Text(), ":")
if zipcode_p[0] == "CEP" {
return zipcode_p[1]
}
return findZipcode(index+1, details)
}
示例2: parseName
func parseName(players *goquery.Selection, position int) string {
if players.Length()-1 >= position {
return players.Eq(position).Text()
}
return ""
}
示例3: FetchDzjy
// FetchDzjy 抓取数据
func FetchDzjy(date time.Time) ([]*dzjyVO, error) {
formt := "http://data.eastmoney.com/dzjy/%s.html"
resp, err := wget.Get(fmt.Sprintf(formt, date.Format("200601")))
if err != nil {
return nil, gos.DoError(err)
}
doc, err := goquery.NewDocumentFromResponse(resp)
if err != nil {
return nil, gos.DoError(err)
}
var td *goquery.Selection
var dzjy *dzjyVO
var dateStr string
var stockCode string
var row db.DataRow
query := db.NewQueryBuilder("stock")
datalist := make([]*dzjyVO, 0)
buy := ""
sell := ""
var priceNow float64
var price float64
var amount float64
var total float64
var length int
doc.Find("#content div.list").Eq(2).Find("table tr.list_eve").Each(func(i int, tr *goquery.Selection) {
td = tr.Find("td")
length = td.Length()
if length == 10 {
dateStr = td.Eq(0).Text()
stockCode = td.Eq(1).Text()
} else if length == 9 {
stockCode = td.Eq(0).Text()
}
row, _ = query.Where("code=?", stockCode).QueryOne()
if row.Empty() {
return
}
switch length {
case 10:
priceNow = util.ParseMoney(td.Eq(4).Text())
price = util.ParseMoney(td.Eq(5).Text())
amount = util.ParseMoney(td.Eq(6).Text())
total = util.ParseMoney(td.Eq(7).Text())
buy, err = iconv.ConvertString(td.Eq(8).Text(), "gb2312", "utf-8")
if err != nil {
return
}
sell, err = iconv.ConvertString(td.Eq(9).Text(), "gb2312", "utf-8")
if err != nil {
return
}
case 9:
priceNow = util.ParseMoney(td.Eq(3).Text())
price = util.ParseMoney(td.Eq(4).Text())
amount = util.ParseMoney(td.Eq(5).Text())
total = util.ParseMoney(td.Eq(6).Text())
buy, err = iconv.ConvertString(td.Eq(7).Text(), "gb2312", "utf-8")
if err != nil {
return
}
sell, err = iconv.ConvertString(td.Eq(8).Text(), "gb2312", "utf-8")
if err != nil {
return
}
case 5:
price = util.ParseMoney(td.Eq(0).Text())
amount = util.ParseMoney(td.Eq(1).Text())
total = util.ParseMoney(td.Eq(2).Text())
buy, err = iconv.ConvertString(td.Eq(3).Text(), "gb2312", "utf-8")
if err != nil {
return
}
sell, err = iconv.ConvertString(td.Eq(4).Text(), "gb2312", "utf-8")
if err != nil {
return
}
default:
return
}
dzjy = &dzjyVO{
StockID: row.GetInt64("id"),
Date: dateStr,
PriceNow: priceNow,
Price: price,
Amount: amount,
Total: total,
Buy: buy,
Sell: sell,
}
datalist = append(datalist, dzjy)
//.........这里部分代码省略.........