本文整理汇总了Golang中github.com/PuerkitoBio/goquery.Document.Attr方法的典型用法代码示例。如果您正苦于以下问题:Golang Document.Attr方法的具体用法?Golang Document.Attr怎么用?Golang Document.Attr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/PuerkitoBio/goquery.Document
的用法示例。
在下文中一共展示了Document.Attr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseOrderListPage
func parseOrderListPage(s *goquery.Document) ([]Order, bool, error) {
c := s.Find(".container").First()
t := c.Find("div").First().Text()
if t != ">注文情報(一覧)<" && t != ">注文情報(検索)<" {
return nil, false, fmt.Errorf("cannot open \"注文情報(一覧)\", but %#v", t)
}
// タイトル行の削除
c.Find("hr").First().Next().PrevAll().Remove()
results := []Order{}
c.Find("a").Each(
func(_ int, s *goquery.Selection) {
href, ok := s.Attr("href")
if !ok || !strings.HasPrefix(href, "../otc/C003.html?") {
return
}
u, err := url.Parse(href)
if err != nil || u.RawQuery == "" {
return
}
v, err := url.ParseQuery(u.RawQuery)
results = append(results, Order{
OrderId: v.Get("order_id"),
OrderMethod: v.Get("order_method"),
})
})
return results, c.Find("a[accesskey=\"#\"]").Length() == 1, nil
}
示例2: parsePositionListPage
func parsePositionListPage(s *goquery.Document) ([]Position, bool, error) {
c := s.Find(".container").First()
t := c.Find("div").First().Text()
if t != ">ポジション情報(一覧)<" && t != ">ポジション情報(検索)<" {
return nil, false, fmt.Errorf("cannot open \"ポジション情報(一覧)\", but %#v", t)
}
results := []Position{}
c.Find("a").Each(
func(_ int, s *goquery.Selection) {
href, ok := s.Attr("href")
if !ok || !strings.HasPrefix(href, "C304.html") {
return
}
u, err := url.Parse(href)
if err != nil || u.RawQuery == "" {
return
}
v, err := url.ParseQuery(u.RawQuery)
results = append(results, Position{
PositionId: v.Get("position_id"),
})
})
return results, c.Find("a[accesskey=\"#\"]").Length() == 1, nil
}
示例3: GetMetaLanguage
// GetMetaLanguage returns the meta language set in the source, if the article has one
func (extr *ContentExtractor) GetMetaLanguage(document *goquery.Document) string {
language := ""
shtml := document.Find("html")
attr, _ := shtml.Attr("lang")
if attr == "" {
attr, _ = document.Attr("lang")
}
if attr == "" {
selection := document.Find("meta").EachWithBreak(func(i int, s *goquery.Selection) bool {
exists := false
attr, exists = s.Attr("http-equiv")
if exists && attr == "content-language" {
return false
}
return true
})
if selection != nil {
attr, _ = selection.Attr("content")
}
}
idx := strings.LastIndex(attr, "-")
if idx == -1 {
language = attr
} else {
language = attr[0:idx]
}
_, ok := sw[language]
if language == "" || !ok {
language = extr.config.stopWords.SimpleLanguageDetector(shtml.Text())
if language == "" {
language = defaultLanguage
}
}
extr.config.targetLanguage = language
return language
}
示例4: 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
}