You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
758 B

  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "bytes"
  7. "github.com/PuerkitoBio/goquery"
  8. )
  9. type HtmlDoc struct {
  10. doc *goquery.Document
  11. }
  12. func NewHtmlParser(content []byte) (*HtmlDoc, error) {
  13. doc, err := goquery.NewDocumentFromReader(bytes.NewReader(content))
  14. if err != nil {
  15. return nil, err
  16. }
  17. return &HtmlDoc{doc: doc}, nil
  18. }
  19. func (doc *HtmlDoc) GetInputValueById(id string) string {
  20. text, _ := doc.doc.Find("#" + id).Attr("value")
  21. return text
  22. }
  23. func (doc *HtmlDoc) GetInputValueByName(name string) string {
  24. text, _ := doc.doc.Find("input[name=\"" + name + "\"]").Attr("value")
  25. return text
  26. }