Exemple #1
0
func (this *Pixivspy) checkLogin() bool {
	req, err := http.NewRequest(config.Info.CheckLoginPageUrl.Method,
		config.Info.CheckLoginPageUrl.Url,
		nil)

	if err != nil {
		log4go.Debug("可能也许大概内存不足导致发送请求失败!")
		os.Exit(-1)
	}

	log4go.Info("登录中")

	this.setHtmlHeader(req)

	body, err := this.download(req)
	if err != nil {
		return false
	}

	query, err := goquery.ParseString(string(body))
	if err != nil {
		log4go.Error("解析登录数据失败", this.username)
		return false
	}

	item := query.Find(".user")
	if item.Length() == 0 {
		return false
	}

	return true
}
Exemple #2
0
func (this *Pixivspy) parseMemberIllusts(memberID string) []*pixivIllust {
	works := []*pixivIllust{}
	pageNum := 1

	for {
		page, ok := this.downloadMemberPage(memberID, pageNum)

		if ok {
			log4go.Debug("正在解析[%s]P主作品第[%d]页", memberID, pageNum)

			query, err := goquery.ParseString(string(page))
			if err != nil {
				log4go.Debug("解析[%s]P主作品第[%d]页失败", memberID, pageNum)
				return works
			}

			workItem := query.Find(".work")
			if workItem.Length() == 0 {
				log4go.Info("已经访问到最后一页")
				return works
			}
			illustNameItem := query.Find("a h1.title")

			for i := 0; i < workItem.Length(); i++ {
				href := workItem.Eq(i).Attr("href")
				class := workItem.Eq(i).Attr("class")
				id := href[strings.Index(href, "illust_id=")+len("illust_id="):]

				works = append(works,
					&pixivIllust{
						href:  href,
						class: class,
						id:    id,
						title: illustNameItem.Eq(i).Text(),
					})
			}
			pageNum++
		} else {
			log4go.Warn("访问[%s]P主主页失败", memberID)
			return works
		}
	}

	return works
}
Exemple #3
0
func main() {
	SetLog()
	defer log.Close()

	var name = "skoo"
	log.Debug("log4go by %s", name)
	log.Info("log4go by %s", name)
	log.Warn("log4go by %s", name)
	log.Error("log4go by %s", name)
	log.Fatal("log4go by %s", name)
}
func main() {
	// Load the configuration (isn't this easy?)
	l4g.LoadConfiguration("example.xml")

	l4g.Finest("This will only go to those of you really cool UDP kids!  If you change enabled=true.")
	l4g.Info("About .....")
	l4g.Trace("About that time, eh chaps?")
	l4g.Trace("About that time, eh chaps?")
	l4g.Trace("About that time, eh chaps?")
	l4g.Debug("About that time, eh chaps?")
	l4g.Info("About that time, eh chaps?")
	l4g.Warn("About that time, eh chaps?")
	select {}
}
Exemple #5
0
func main() {
	SetLog()
	defer log.Close()

	var name = "skoo"

	for {
		log.Debug("log4go by %s", name)
		log.Info("log4go by %s", name)
		log.Warn("log4go by %s", name)
		log.Error("log4go by %s", name)
		log.Fatal("log4go by %s", name)

		time.Sleep(time.Second * 1)
	}
}
Exemple #6
0
func (this *Pixivspy) parseMemberNameFromMemberID(memberID string) string {
	page, ok := this.downloadMemberPage(memberID, 1)

	if ok {
		query, err := goquery.ParseString(string(page))
		if err != nil {
			log4go.Debug("解析[%s]P主主页失败", memberID)
			return "Unkown"
		}

		workItem := query.Find(".user")

		return workItem.Text()
	}

	return "Unkown"
}
Exemple #7
0
func (this *Pixivspy) Login() bool {
	postValue := url.Values{}
	postValue.Set("mode", "login")
	postValue.Add("pixiv_id", this.username)
	postValue.Add("pass", this.password)
	postValue.Add("skip", "1")

	req, err := http.NewRequest(config.Info.LoginPageUrl.Method,
		config.Info.LoginPageUrl.Url,
		strings.NewReader(postValue.Encode()))

	if err != nil {
		log4go.Debug("可能也许大概内存不足导致发送请求失败!")
		return false
	}

	log4go.Info("正在登录: %s", this.username)

	this.setHtmlHeader(req)

	client := http.Client{Jar: this.cookie}

	resp := &http.Response{}
	retry := 0
	for retry < 5 {
		resp, err = client.Do(req)
		if err == nil {
			break
		}

		if resp != nil {
			resp.Body.Close()
		}

		retry++
	}

	if retry == 5 || !this.checkLogin() {
		log4go.Error("帐号: %s 登录失败", this.username)
		return false
	}

	log4go.Info("帐号: %s 登录成功", this.username)

	return true
}
Exemple #8
0
func (this *Pixivspy) parseStarPage(url string) []string {
	members := []string{}

	for i := 1; true; i++ {
		url = fmt.Sprintf(url+"&p=%d", i)

		req, _ := http.NewRequest(config.Info.StarPageUrl.Method, url, nil)

		this.setHtmlHeader(req)

		page, err := this.download(req)
		if page == nil || err != nil {
			log4go.Error("下载关注页面失败")
			break
		}

		query, err := goquery.ParseString(string(page))
		if err != nil {
			log4go.Debug("解析关注页面失败")
			break
		}

		membersItem := query.Find("div.userdata")

		if membersItem.Length() == 0 {
			break
		}

		log4go.Info("正在解析第[%d]页关注页面", i)

		for i := 0; i < membersItem.Length(); i++ {
			a := membersItem.Eq(i)
			memberID := a.Find("a").Attr("data-user_id")
			members = append(members, memberID)
		}
	}

	return members
}
Exemple #9
0
func (this *Pixivspy) parseIllustPage(illust *pixivIllust) (string, bool) {
	//如果是图集,则暂不处理
	//图集的话,需要打开页面后,再次进行一次页面的Parser
	if strings.Index(illust.class, "multiple") > 0 {
		return "", true
	}

	log4go.Debug("正在解析[%s]图片集", illust.title)

	req, _ := http.NewRequest(config.Info.HostPageUrl.Method,
		config.Info.HostPageUrl.Url+illust.href,
		nil)

	this.setHtmlHeader(req)

	page, err := this.download(req)

	if page == nil || err != nil {
		return "", false
	}

	return string(page), true
}