package main import ( "io/ioutil" "os" "regexp" "testing" "time" "github.com/474420502/hunter" "github.com/lestrrat-go/libxml2" ) func TestCase0(t *testing.T) { f, err := os.Open("./test.html") if err != nil { panic(err) } data, err := ioutil.ReadAll(f) if err != nil { panic(err) } matheslist := regexp.MustCompile(`TagButton__Button[^>]+>(.{1,100})" xresult, err := doc.Find("/html/head") ele, err := doc.CreateElement(`META`) if err != nil { panic(err) } ele.SetAttribute("charset", "utf-8") if err != nil { panic(err) } iter := xresult.NodeIter() if iter.Next() { n := iter.Node() err = n.AddChild(ele) // childs, err := n.ChildNodes() if err != nil { t.Error(err) } t.Error(n) } xr, err := doc.Find("//h1[ contains(@class, 'MovieTitle__Title')]") if err != nil { panic(nil) } t.Error(xr) } func TestUserName(t *testing.T) { f, err := os.Open("test.html") if err != nil { panic(err) } data, err := ioutil.ReadAll(f) if err != nil { panic(err) } extractor := hunter.NewExtractor(data) xp, err := extractor.XPathResult("//p[ contains(@class, 'c-global__user__profile__list__name__text')]/text()") if err != nil { t.Error(err) } else { if xp.NodeIter().Next() { userName := xp.String() t.Error(userName) } } } func TestExtractor(t *testing.T) { oe := &OpenrecExtractor{} oe.Execute() }