Пример #1
0
func (s *XpathConfig) ParseContentByXpath(html []byte) (result map[string]interface{}, err error) {
	result = GetData(html, map[string]interface{}{"list": s.XpathList}, s.XpathDetail)
	// 采集文章数量
	c := ppDownloader.GetData([]byte(html), map[string]interface{}{"count": s.XpathNewsCount})
	result["count"] = c["count"]
	return
}
Пример #2
0
func GetRandom_token(x *utils.Conf, xpath string) (randrom_token string, err error) {
	pp := ppDownloader.New(x.Header)
	resp, err := pp.Get(x.Header.Host)
	if err != nil {
		return
	}
	result := ppDownloader.GetData(resp.Body, xpath)
	randrom_token = result["random_token"]
	if randrom_token == "" {
		err := errors.New("token失败")
		return "", err
	}
	return
}
Пример #3
0
func GetData(body []byte, xpathList map[string]interface{}, xpathChild map[string]interface{}) (result map[string]interface{}) {
	doc, _ := gokogiri.ParseHtml(body)
	defer doc.Free()
	result = map[string]interface{}{}
	for nodeName, v := range xpathList {
		xps := xpath.Compile(v.(string))
		ss, _ := doc.Root().Search(xps)
		for k, s := range ss {
			innerHtml := s.InnerHtml()
			item := make(map[string]interface{})
			item[nodeName] = innerHtml
			list := ppDownloader.GetData([]byte(innerHtml), xpathChild)
			result[strconv.Itoa(k)] = list
		}
	}

	return
}