Skip to content

Commit 3cddb6b

Browse files
authored
fix(driver): Handle Lanzou anti-crawler challenge by recalculating cookies (#9364)
- Detect and solve `acw_sc__v2` challenge to bypass anti-crawler validation - Refactored request header initialization logic for clarity
1 parent ce41587 commit 3cddb6b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

drivers/lanzou/util.go

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,17 +430,35 @@ func (d *LanZou) getFilesByShareUrl(shareID, pwd string, sharePageData string) (
430430
file.Time = timeFindReg.FindString(sharePageData)
431431

432432
// 重定向获取真实链接
433-
res, err := base.NoRedirectClient.R().SetHeaders(map[string]string{
433+
headers := map[string]string{
434434
"accept-language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
435-
}).Get(downloadUrl)
435+
}
436+
res, err := base.NoRedirectClient.R().SetHeaders(headers).Get(downloadUrl)
436437
if err != nil {
437438
return nil, err
438439
}
439440

441+
rPageData := res.String()
442+
if findAcwScV2Reg.MatchString(rPageData) {
443+
log.Debug("lanzou: detected acw_sc__v2 challenge, recalculating cookie")
444+
acwScV2, err := CalcAcwScV2(rPageData)
445+
if err != nil {
446+
return nil, err
447+
}
448+
// retry with calculated cookie to bypass anti-crawler validation
449+
res, err = base.NoRedirectClient.R().
450+
SetHeaders(headers).
451+
SetCookie(&http.Cookie{Name: "acw_sc__v2", Value: acwScV2}).
452+
Get(downloadUrl)
453+
if err != nil {
454+
return nil, err
455+
}
456+
rPageData = res.String()
457+
}
458+
440459
file.Url = res.Header().Get("location")
441460

442461
// 触发验证
443-
rPageData := res.String()
444462
if res.StatusCode() != 302 {
445463
param, err = htmlJsonToMap(rPageData)
446464
if err != nil {

0 commit comments

Comments
 (0)