func FetchTrByAjax(idx int, schedule_fenxi_id int, date string, home string) { odd_html := myinit.GetOddItemFromAjax(idx, schedule_fenxi_id) // fmt.Println(odd_html) // fmt.Println(pan_html_obj.HtmlAll()) table_string := "<table>" + odd_html + "</table>" html_obj, _ := goquery.ParseString(table_string) // fmt.Println("=====") odds_tr := html_obj.Find("table tbody tr") pan_int_info := make(map[string]int) pan_float_info := make(map[string]float32) pan_string_info := make(map[string]string) pan_string_info["schedule_date"] = date pan_string_info["schedule_home"] = home for i := 0; i < odds_tr.Length(); i++ { tr_item := odds_tr.Eq(i) td_of_company := tr_item.Find("td").Eq(1) if td_of_company.Find("p a").Attr("title") == "" { continue } pan_string_info["company_name"] = td_of_company.Find("p a").Attr("title") table_of_pan_detail := tr_item.Find("td .pl_table_data") table_of_opentime_pan := table_of_pan_detail.Eq(1) tds_of_opentime_pan_table := table_of_opentime_pan.Find("tbody tr td") open_pan_32, _ := strconv.ParseFloat(tds_of_opentime_pan_table.Eq(1).Attr("ref"), 32) pan_float_info["open_pan"] = float32(open_pan_32) pan_string_info["open_pan_desc"] = tds_of_opentime_pan_table.Eq(1).Text() table_of_realtime_pan := table_of_pan_detail.Eq(0) tds_of_realtime_pan_table := table_of_realtime_pan.Find("tbody tr td") real_pan_32, _ := strconv.ParseFloat(tds_of_realtime_pan_table.Eq(1).Attr("ref"), 32) pan_float_info["real_pan"] = float32(real_pan_32) pan_string_info["real_pan_desc"] = tds_of_realtime_pan_table.Eq(1).Text() td_item_of_real_pan := tds_of_realtime_pan_table.Eq(1) home_pan_change_type := td_item_of_real_pan.Find("font").Text() home_pan_change_type = strings.TrimSpace(home_pan_change_type) pan_int_info["home_pan_change_type"] = 0 if home_pan_change_type == "升" { pan_int_info["home_pan_change_type"] = 1 pan_string_info["home_pan_change_type_desc"] = home_pan_change_type } if home_pan_change_type == "降" { pan_int_info["home_pan_change_type"] = -1 pan_string_info["home_pan_change_type_desc"] = home_pan_change_type } real_pan_string := strings.Replace(pan_string_info["real_pan_desc"], pan_string_info["home_pan_change_type_desc"], "", -1) real_pan_desc := strings.TrimSpace(real_pan_string) fmt.Println("====here====") fmt.Println("date:", pan_string_info["schedule_date"], pan_string_info["schedule_home"], pan_string_info["company_name"]) fmt.Println(idx + i) // if(real_pan_desc==""){ // fmt.Println("trtime:") // fmt.Println(tr_item.HtmlAll()) // }else{ // fmt.Println("oktrtime:") // fmt.Println(tr_item.HtmlAll()) // } // fmt.Println("open:", pan_string_info["open_pan_desc"], pan_float_info["open_pan"]) // fmt.Println("real:", real_pan_desc, pan_float_info["real_pan"]) // fmt.Println("real desc:", pan_string_info["real_pan_desc"], pan_string_info["home_pan_change_type_desc"]) fmt.Println("++end here+++") panmap.Add(pan_string_info["open_pan_desc"], pan_float_info["open_pan"]) panmap.Add(real_pan_desc, pan_float_info["real_pan"]) } if odds_tr.Length() >= 30 { FetchTrByAjax(idx+30, schedule_fenxi_id, pan_string_info["schedule_date"], pan_string_info["schedule_home"]) } }
func GetPanValue(schedule_pan_url string, schedule_fenxi_id int, schedule_string_info map[string]string, date string) (res bool) { pan_int_info := make(map[string]int) pan_float_info := make(map[string]float32) pan_string_info := make(map[string]string) pan_html_obj, _ := goquery.ParseUrl(schedule_pan_url) schedule_item := pan_html_obj.Find(".odds_hd_cont table tbody tr td") home_td := schedule_item.Eq(0) pan_string_info["schedule_date"] = schedule_string_info["schedule_date"] pan_string_info["schedule_home"] = common.ConvToGB(home_td.Find("ul li a").Text()) odds_tr := pan_html_obj.Find(".table_cont table tbody tr") for i := 0; i < odds_tr.Length(); i++ { tr_item := odds_tr.Eq(i) td_of_company := tr_item.Find("td").Eq(1) if td_of_company.Find("p a").Attr("title") == "" { continue } pan_string_info["company_name"] = common.ConvToGB(td_of_company.Find("p a").Attr("title")) table_of_pan_detail := tr_item.Find("td .pl_table_data") table_of_opentime_pan := table_of_pan_detail.Eq(1) tds_of_opentime_pan_table := table_of_opentime_pan.Find("tbody tr td") open_pan_32, _ := strconv.ParseFloat(tds_of_opentime_pan_table.Eq(1).Attr("ref"), 32) pan_float_info["open_pan"] = float32(open_pan_32) pan_string_info["open_pan_desc"] = common.ConvToGB(tds_of_opentime_pan_table.Eq(1).Text()) table_of_realtime_pan := table_of_pan_detail.Eq(0) tds_of_realtime_pan_table := table_of_realtime_pan.Find("tbody tr td") real_pan_32, _ := strconv.ParseFloat(tds_of_realtime_pan_table.Eq(1).Attr("ref"), 32) pan_float_info["real_pan"] = float32(real_pan_32) pan_string_info["real_pan_desc"] = common.ConvToGB(tds_of_realtime_pan_table.Eq(1).Text()) td_item_of_real_pan := tds_of_realtime_pan_table.Eq(1) home_pan_change_type := common.ConvToGB(td_item_of_real_pan.Find("font").Text()) home_pan_change_type = strings.TrimSpace(home_pan_change_type) pan_int_info["home_pan_change_type"] = 0 if home_pan_change_type == "升" { pan_int_info["home_pan_change_type"] = 1 pan_string_info["home_pan_change_type_desc"] = home_pan_change_type } if home_pan_change_type == "降" { pan_int_info["home_pan_change_type"] = -1 pan_string_info["home_pan_change_type_desc"] = home_pan_change_type } real_pan_string := strings.Replace(pan_string_info["real_pan_desc"], pan_string_info["home_pan_change_type_desc"], "", -1) real_pan_desc := strings.TrimSpace(real_pan_string) fmt.Println("====here====") fmt.Println(i) fmt.Println("date:", pan_string_info["schedule_date"], pan_string_info["schedule_home"], pan_string_info["company_name"]) // fmt.Println("open:", pan_string_info["open_pan_desc"], pan_float_info["open_pan"]) // fmt.Println("real:", real_pan_desc, pan_float_info["real_pan"]) // fmt.Println("real desc:", pan_string_info["real_pan_desc"], pan_string_info["home_pan_change_type_desc"]) fmt.Println("++end here+++") panmap.Add(pan_string_info["open_pan_desc"], pan_float_info["open_pan"]) panmap.Add(real_pan_desc, pan_float_info["real_pan"]) } if odds_tr.Length() >= 30 { FetchTrByAjax(30, schedule_fenxi_id, pan_string_info["schedule_date"], pan_string_info["schedule_home"]) } return true }