diff --git a/backend/data/stock_data_api.go b/backend/data/stock_data_api.go index f126458..4df85a4 100644 --- a/backend/data/stock_data_api.go +++ b/backend/data/stock_data_api.go @@ -646,11 +646,18 @@ func SearchStockInfo(stock, msgType string, crawlTimeOut int64) *[]string { }(ctx) var htmlContent string url := fmt.Sprintf("https://www.cls.cn/searchPage?keyword=%s&type=%s", stock, msgType) + sel := ".subject-interest-list" + if msgType == "depth" { + sel = ".subject-interest-list" + } + if msgType == "telegram" { + sel = ".search-telegraph-list" + } err := chromedp.Run(ctx, chromedp.Navigate(url), // 等待页面加载完成,可以根据需要调整等待时间 //chromedp.Sleep(3*time.Second), - chromedp.WaitVisible(".search-content", chromedp.ByQuery), + chromedp.WaitVisible(sel, chromedp.ByQuery), chromedp.OuterHTML("html", &htmlContent, chromedp.ByQuery), ) if err != nil { @@ -663,7 +670,7 @@ func SearchStockInfo(stock, msgType string, crawlTimeOut int64) *[]string { return &[]string{} } var messages []string - document.Find(".search-content").Each(func(i int, selection *goquery.Selection) { + document.Find(".search-telegraph-list,.subject-interest-list").Each(func(i int, selection *goquery.Selection) { text := strutil.RemoveNonPrintable(selection.Text()) if strings.Contains(text, stock) { messages = append(messages, text) diff --git a/backend/data/stock_data_api_test.go b/backend/data/stock_data_api_test.go index a4c59e6..ed86547 100644 --- a/backend/data/stock_data_api_test.go +++ b/backend/data/stock_data_api_test.go @@ -20,16 +20,16 @@ import ( //----------------------------------------------------------------------------------- func TestGetTelegraph(t *testing.T) { - GetTelegraphList() + GetTelegraphList(30) } func TestGetFinancialReports(t *testing.T) { - GetFinancialReports("sz000802") + GetFinancialReports("sz000802", 30) } func TestGetTelegraphSearch(t *testing.T) { //url := "https://www.cls.cn/searchPage?keyword=%E9%97%BB%E6%B3%B0%E7%A7%91%E6%8A%80&type=telegram" - messages := SearchStockInfo("闻泰科技", "telegram") + messages := SearchStockInfo("闻泰科技", "depth", 30) for _, message := range *messages { logger.SugaredLogger.Info(message) } @@ -41,7 +41,7 @@ func TestSearchStockInfoByCode(t *testing.T) { } func TestSearchStockPriceInfo(t *testing.T) { - SearchStockPriceInfo("sh600745") + SearchStockPriceInfo("sh600745", 30) } func TestParseFullSingleStockData(t *testing.T) {