intimate/extractor/openrec/openrec_test.go
2020-07-13 18:10:48 +08:00

74 lines
1.7 KiB
Go

package main
import (
"bytes"
"encoding/gob"
"net/http"
"testing"
"github.com/474420502/requests"
)
func TestExtractor(t *testing.T) {
ses := requests.NewSession()
wf := ses.Get("https://www.openrec.tv/user/Riowh/supporters")
wf.Execute()
// t.Error(ses.GetCookies(wf.GetParsedURL()))
buf := bytes.Buffer{}
encoder := gob.NewEncoder(&buf)
encoder.Encode(ses.GetCookies(wf.GetParsedURL()))
var cookies []*http.Cookie
decoder := gob.NewDecoder(&buf)
t.Error(decoder.Decode(&cookies))
t.Error(cookies)
// collect := intimate.NewExtractorStore()
// store := intimate.NewSourceStore("source_openrec")
// source, err := store.Pop(string(intimate.TTOpenrecRanking), 100)
// if source != nil {
// defer store.Restore(source)
// }
// if err != nil {
// t.Error(err)
// }
// sdata := source.GetExt().([]byte)
// if gjson.ValidBytes(sdata) {
// result := gjson.ParseBytes(sdata)
// m := result.Map()
// user := m["user"]
// ai := &intimate.CollectLog{}
// extractor := hunter.NewExtractor([]byte(user.Str))
// xp, err := extractor.XPathResult("//p[@class='c-global__user__count__row__right js-userCountFollowers']/text()")
// if err != nil {
// t.Error(err)
// }
// if !xp.NodeIter().Next() {
// t.Error("不存在粉丝数")
// }
// followers := strings.ReplaceAll(xp.String(), ",", "")
// followersInt, err := strconv.Atoi(followers)
// if err != nil {
// t.Error(err)
// }
// ai.SetPlatform(string(intimate.Popenrec))
// ai.SetFollowers(sql.NullInt32{Int32: int32(followersInt), Valid: true})
// ai.SetAnchorId(source.GetSource().String)
// collect.InsertCollectLog(ai)
// } else {
// t.Error("data is not json:\n", string(sdata))
// }
}