|
@@ -1,4 +1,4 @@
|
|
|
-package main
|
|
|
+package liangyou
|
|
|
|
|
|
import (
|
|
|
"context"
|
|
@@ -21,19 +21,12 @@ const (
|
|
|
lyLoginPath = "https://www.fao.com.cn/"
|
|
|
)
|
|
|
|
|
|
-// UserInfo 登录用户信息
|
|
|
-type UserInfo struct {
|
|
|
- Username string
|
|
|
- Password string
|
|
|
-}
|
|
|
-
|
|
|
-func main() {
|
|
|
-
|
|
|
+func LyDataDeal(cont context.Context) (err error) {
|
|
|
// 读取 JSON 文件
|
|
|
- configFile, err := os.ReadFile("D:\\go\\workspace1\\eta_crawler\\static\\liangyou.json")
|
|
|
+ configFile, err := os.ReadFile(utils.LY_JSON_PATH)
|
|
|
if err != nil {
|
|
|
fmt.Printf("读取配置文件错误: %v\n", err)
|
|
|
- return
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
// 定义通用的 map 结构体来解析 JSON
|
|
@@ -43,7 +36,7 @@ func main() {
|
|
|
err = json.Unmarshal(configFile, &data)
|
|
|
if err != nil {
|
|
|
fmt.Printf("解析配置文件错误: %v\n", err)
|
|
|
- return
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
// 打印解析后的数据以验证
|
|
@@ -65,7 +58,7 @@ func main() {
|
|
|
err = login(ctx)
|
|
|
if err != nil {
|
|
|
fmt.Printf("登录错误: %v\n", err)
|
|
|
- return
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
// 遍历配置并爬取数据
|
|
@@ -80,20 +73,18 @@ func main() {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ return nil
|
|
|
}
|
|
|
|
|
|
func login(ctx context.Context) error {
|
|
|
- userInfo := UserInfo{
|
|
|
- Username: "13633849418",
|
|
|
- Password: "828384Abc@",
|
|
|
- }
|
|
|
+
|
|
|
return chromedp.Run(ctx,
|
|
|
chromedp.Navigate(lyLoginPath),
|
|
|
chromedp.Sleep(5*time.Second),
|
|
|
chromedp.Click(`a[id="btnLogin"]`, chromedp.ByQuery),
|
|
|
chromedp.Sleep(2*time.Second),
|
|
|
- chromedp.SetValue(`input[id="userName"]`, userInfo.Username, chromedp.ByQuery),
|
|
|
- chromedp.SetValue(`input[id="pwd"]`, userInfo.Password, chromedp.ByQuery),
|
|
|
+ chromedp.SetValue(`input[id="userName"]`, utils.LY_USERNAME, chromedp.ByQuery),
|
|
|
+ chromedp.SetValue(`input[id="pwd"]`, utils.LY_PASSWORD, chromedp.ByQuery),
|
|
|
chromedp.Sleep(2*time.Second),
|
|
|
chromedp.Click(`input[id="btn_Login"]`, chromedp.ByQuery),
|
|
|
chromedp.Sleep(5*time.Second),
|
|
@@ -147,11 +138,9 @@ func fetchReportData(ctx context.Context, product, category, report string, keyw
|
|
|
reportURLs := extractReportURLs(htmlContent, report)
|
|
|
allReportURLs = append(allReportURLs, reportURLs...)
|
|
|
|
|
|
- // todo 测试环境跑部分数据,上线放开
|
|
|
- break
|
|
|
// Check if next page button is disabled
|
|
|
- // todo 测试环境跑部分数据,上线放开
|
|
|
- /*var nextPageDisabled bool
|
|
|
+ // 测试环境跑部分数据,上线放开...
|
|
|
+ var nextPageDisabled bool
|
|
|
err = chromedp.Run(ctx,
|
|
|
chromedp.Evaluate(`document.querySelector('div.my-page-next').classList.contains('my-page-forbid')`, &nextPageDisabled),
|
|
|
)
|
|
@@ -172,7 +161,6 @@ func fetchReportData(ctx context.Context, product, category, report string, keyw
|
|
|
if err != nil {
|
|
|
return err
|
|
|
}
|
|
|
- */
|
|
|
}
|
|
|
|
|
|
logs.Info("所有报告 URLs: %s: %s: %v", product, category, allReportURLs)
|