mirror of
https://github.com/ArvinLovegood/go-stock.git
synced 2025-07-19 00:00:09 +08:00
refactor(stock_data):优化股票信息搜索功能
- 修改 SearchStockInfo 函数,增加对不同消息类型的处理 - 更新页面等待逻辑,根据消息类型选择不同的选择器 - 调整测试函数,增加时间参数
This commit is contained in:
parent
4fac915778
commit
6be5c0fa05
@ -645,7 +645,7 @@ 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)
|
||||
url := fmt.Sprintf("https://www.cls.cn/searchPage?keyword=%s&type=%s", strutil.RemoveNonPrintable(stock), msgType)
|
||||
sel := ".subject-interest-list"
|
||||
if msgType == "depth" {
|
||||
sel = ".subject-interest-list"
|
||||
@ -656,8 +656,8 @@ func SearchStockInfo(stock, msgType string, crawlTimeOut int64) *[]string {
|
||||
err := chromedp.Run(ctx,
|
||||
chromedp.Navigate(url),
|
||||
// 等待页面加载完成,可以根据需要调整等待时间
|
||||
//chromedp.Sleep(3*time.Second),
|
||||
chromedp.WaitVisible(sel, chromedp.ByQuery),
|
||||
chromedp.Sleep(3*time.Second),
|
||||
chromedp.OuterHTML("html", &htmlContent, chromedp.ByQuery),
|
||||
)
|
||||
if err != nil {
|
||||
@ -672,10 +672,10 @@ func SearchStockInfo(stock, msgType string, crawlTimeOut int64) *[]string {
|
||||
var messages []string
|
||||
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)
|
||||
logger.SugaredLogger.Infof("搜索到消息-%s: %s", msgType, text)
|
||||
}
|
||||
//if strings.Contains(text, strutil.RemoveNonPrintable(stock)) {
|
||||
messages = append(messages, text)
|
||||
logger.SugaredLogger.Infof("搜索到消息-%s: %s", msgType, text)
|
||||
//}
|
||||
})
|
||||
return &messages
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ func TestGetFinancialReports(t *testing.T) {
|
||||
|
||||
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("闻泰科技", "depth", 30)
|
||||
messages := SearchStockInfo("新 希 望", "telegram", 30)
|
||||
for _, message := range *messages {
|
||||
logger.SugaredLogger.Info(message)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user