|
@@ -288,12 +288,13 @@ func (s *Spider) DownListPageItem() (errs interface{}) {
|
|
href := fmt.Sprint(tmp["href"])
|
|
href := fmt.Sprint(tmp["href"])
|
|
if len(href) > 5 { //有效数据
|
|
if len(href) > 5 { //有效数据
|
|
db := HexToBigIntMod(href) //根据href的哈希值选择Redis的db
|
|
db := HexToBigIntMod(href) //根据href的哈希值选择Redis的db
|
|
|
|
+ hashHref := HexText(href)
|
|
//增量(redis默认db0)
|
|
//增量(redis默认db0)
|
|
util.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*30)
|
|
util.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*30)
|
|
//全量(判断是否已存在防止覆盖id)
|
|
//全量(判断是否已存在防止覆盖id)
|
|
- isExist, _ := util.ExistRedis("title_repeat_fulljudgement", db, "url_repeat_"+href)
|
|
|
|
|
|
+ isExist, _ := util.ExistRedis("title_repeat_fulljudgement", db, hashHref)
|
|
if !isExist {
|
|
if !isExist {
|
|
- util.PutRedis("title_repeat_fulljudgement", db, "url_repeat_"+href, "", -1)
|
|
|
|
|
|
+ util.PutRedis("title_repeat_fulljudgement", db, hashHref, "", -1)
|
|
}
|
|
}
|
|
list = append(list, tmp)
|
|
list = append(list, tmp)
|
|
}
|
|
}
|
|
@@ -408,8 +409,9 @@ func (s *Spider) HistoricalMendDownloadDetailItem(p interface{}) {
|
|
return
|
|
return
|
|
}
|
|
}
|
|
db := HexToBigIntMod(href)
|
|
db := HexToBigIntMod(href)
|
|
- SaveListPageData(paramdata) //存储采集记录
|
|
|
|
- isExist, _ := util.ExistRedis("title_repeat_fulljudgement", db, "url_repeat_"+href) //取全量redis
|
|
|
|
|
|
+ hashHref := HexText(href)
|
|
|
|
+ SaveListPageData(paramdata) //存储采集记录
|
|
|
|
+ isExist, _ := util.ExistRedis("title_repeat_fulljudgement", db, hashHref) //取全量redis
|
|
//log.Println("full href:", href, " isExist:", isExist)
|
|
//log.Println("full href:", href, " isExist:", isExist)
|
|
logger.Debug("full href:", href, " isExist:", isExist)
|
|
logger.Debug("full href:", href, " isExist:", isExist)
|
|
if !s.IsMustDownload && isExist { //非强制下载redis中存在,结束
|
|
if !s.IsMustDownload && isExist { //非强制下载redis中存在,结束
|
|
@@ -510,9 +512,10 @@ func (s *Spider) DownloadDetailItem(p interface{}, num *int) {
|
|
util.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*30)
|
|
util.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*30)
|
|
//全量
|
|
//全量
|
|
db := HexToBigIntMod(href)
|
|
db := HexToBigIntMod(href)
|
|
- isExist, _ := util.ExistRedis("title_repeat_fulljudgement", db, "url_repeat_"+href)
|
|
|
|
|
|
+ hashHref := HexText(href)
|
|
|
|
+ isExist, _ := util.ExistRedis("title_repeat_fulljudgement", db, hashHref)
|
|
if !isExist {
|
|
if !isExist {
|
|
- util.PutRedis("title_repeat_fulljudgement", db, "url_repeat_"+href, "", -1)
|
|
|
|
|
|
+ util.PutRedis("title_repeat_fulljudgement", db, hashHref, "", -1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
t1 := util.ParseDate2Int64(qu.ObjToString(data["publishtime"]))
|
|
t1 := util.ParseDate2Int64(qu.ObjToString(data["publishtime"]))
|
|
@@ -720,9 +723,10 @@ func (s *Spider) DownloadHighDetail() {
|
|
util.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*30)
|
|
util.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*30)
|
|
//全量
|
|
//全量
|
|
db := HexToBigIntMod(href)
|
|
db := HexToBigIntMod(href)
|
|
- isExist, _ := util.ExistRedis("title_repeat_fulljudgement", db, "url_repeat_"+href)
|
|
|
|
|
|
+ hashHref := HexText(href)
|
|
|
|
+ isExist, _ := util.ExistRedis("title_repeat_fulljudgement", db, hashHref)
|
|
if !isExist {
|
|
if !isExist {
|
|
- util.PutRedis("title_repeat_fulljudgement", db, "url_repeat_"+href, "", -1)
|
|
|
|
|
|
+ util.PutRedis("title_repeat_fulljudgement", db, hashHref, "", -1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if !success { //下载失败更新次数和状态
|
|
if !success { //下载失败更新次数和状态
|
|
@@ -841,9 +845,10 @@ func (s *Spider) DownloadListDetail() {
|
|
util.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*30)
|
|
util.PutRedis("title_repeat_judgement", 0, "url_repeat_"+href, href, 3600*24*30)
|
|
//全量
|
|
//全量
|
|
db := HexToBigIntMod(href)
|
|
db := HexToBigIntMod(href)
|
|
- isExist, _ := util.ExistRedis("title_repeat_fulljudgement", db, "url_repeat_"+href)
|
|
|
|
|
|
+ hashHref := HexText(href)
|
|
|
|
+ isExist, _ := util.ExistRedis("title_repeat_fulljudgement", db, hashHref)
|
|
if !isExist {
|
|
if !isExist {
|
|
- util.PutRedis("title_repeat_fulljudgement", db, "url_repeat_"+href, "", -1)
|
|
|
|
|
|
+ util.PutRedis("title_repeat_fulljudgement", db, hashHref, "", -1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if !success { //下载失败更新次数和状态
|
|
if !success { //下载失败更新次数和状态
|
|
@@ -911,6 +916,13 @@ func HexToBigIntMod(href string) int {
|
|
return int(n.Mod(n, big.NewInt(16)).Int64())
|
|
return int(n.Mod(n, big.NewInt(16)).Int64())
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+//求hash
|
|
|
|
+func HexText(href string) string {
|
|
|
|
+ h := sha256.New()
|
|
|
|
+ h.Write([]byte(href))
|
|
|
|
+ return fmt.Sprintf("%x", h.Sum(nil))
|
|
|
|
+}
|
|
|
|
+
|
|
//func RedisIsExist(href string) bool {
|
|
//func RedisIsExist(href string) bool {
|
|
// isExist := false
|
|
// isExist := false
|
|
// if len(href) > 75 { //取href的哈希判断是否存在
|
|
// if len(href) > 75 { //取href的哈希判断是否存在
|