2017-05-01 19:49:55 -05:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package integrations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
|
2017-05-07 09:40:31 -05:00
|
|
|
"github.com/PuerkitoBio/goquery"
|
2017-05-01 19:49:55 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type HtmlDoc struct {
|
2017-05-07 09:40:31 -05:00
|
|
|
doc *goquery.Document
|
2017-05-01 19:49:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewHtmlParser(content []byte) (*HtmlDoc, error) {
|
2017-05-07 09:40:31 -05:00
|
|
|
doc, err := goquery.NewDocumentFromReader(bytes.NewReader(content))
|
2017-05-01 19:49:55 -05:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &HtmlDoc{doc: doc}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (doc *HtmlDoc) GetInputValueById(id string) string {
|
2017-05-07 09:40:31 -05:00
|
|
|
text, _ := doc.doc.Find("#" + id).Attr("value")
|
|
|
|
return text
|
2017-05-01 19:49:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func (doc *HtmlDoc) GetInputValueByName(name string) string {
|
2017-05-07 09:40:31 -05:00
|
|
|
text, _ := doc.doc.Find("input[name=\"" + name + "\"]").Attr("value")
|
|
|
|
return text
|
2017-05-01 19:49:55 -05:00
|
|
|
}
|