func main() { item_url := "http://item.jd.com/1510479.html" title := "创维(Skyworth) 42E5ERS 42英寸 高清LED窄边平板液晶电视(银色)" url_str := huihui(item_url, title) fmt.Println(url_str) loader := spider.NewLoader() content, err := loader.Send(url_str, "Get", nil) if err != nil { return } // 解析json var data_json map[string]interface{} if err := json.Unmarshal(content, &data_json); err != nil { return } // 判断状态 thisItem := data_json["thisItem"].(map[string]interface{}) list := data_json["urlPriceList"].([]interface{}) for _, val := range list { row := val.(map[string]interface{}) item := row["items"].([]interface{})[0].(map[string]interface{}) inf := spider.Sense{Title: item["name"].(string), Price: item["price"].(string), ItemUrl: item["url"].(string)} inf.GetChannelBySite(row["site"].(string)) inf.GetItemID(item["url"].(string)) inf.GetHistoryPrice() fmt.Println(inf) } fmt.Println(thisItem["price"].(float64)) }
func load(params map[string]string, page int) ([]byte, error) { url := fmt.Sprintf("http://pub.alimama.com/report/getTbkPaymentDetails.json?startTime=%s&endTime=%s&payStatus=%s&queryType=%s&toPage=%d&perPageSize=20", params["startTime"], params["endTime"], params["payStatus"], params["queryType"], page) //get content loader := spider.NewLoader(url, "Get") loader.SetHeader("Cookie", params["cookie"]) loader.SetHeader("Refer", "http://pub.alimama.com/index.htm") return loader.Send(nil) }
func (c *Index) Shop() { url := "http://shop61757191.m.taobao.com/" ld := spider.NewLoader(url, "GET").WithProxy(false) _, err := ld.Send(nil) if err != nil { fmt.Println("...") } c.Json(0, "aa", "data") }