Пример #1
0
        public void AddItme(BaseItemInfo item, string fileName, bool isShop = true)
        {
            string key = item.Created + item.Format + item.Name;

            if (!ShopAllItems.ContainsKey(key))
            {
                ShopAllItems.Add(key, item);
                WriteItem(item, fileName);
            }
            else
            {
                if (isShop)
                {
                    if (shopAllItems[key].PlatformPrice > item.PlatformPrice)
                    {
                        ShopAllItems[key] = item;
                        WriteItem(item, fileName);
                    }
                }
                else
                {
                    if (shopAllItems[key].ShopPrice > item.ShopPrice)
                    {
                        ShopAllItems[key] = item;
                        WriteItem(item, fileName);
                    }
                }
            }
        }
Пример #2
0
        public override void ReadAllItem()
        {
            try
            {
                foreach (string id in AllItemUrl)
                {
                    try
                    {
                        string itemPriceUrl = "http://ad.dabai.7lk.com/custom/price/info";

                        string itemInfoUrl = "https://ad.dabai.7lk.com/medication/detail";

                        string itemInfoPostData = "pid={0}&doctorId=321967&token=9d571f1dc32cadf0ea38";

                        string itemPricePostData = "doctorId=321967&userId=321967&skuId={0}&token=9d571f1dc32cadf0ea38";

                        string content = request.HttpPost(itemInfoUrl, string.Format(itemInfoPostData, id));

                        BaseItemInfo item = GetItem(content);

                        string skuId = CommonFun.GetValue(content, "\"skuId\":", ",");

                        content = request.HttpPost(itemPriceUrl, string.Format(itemPricePostData, skuId));

                        string priceStr = CommonFun.GetValue(content, "\"priceMin\":", ",");

                        item.ShopPrice = string.IsNullOrEmpty(priceStr) ? 0 : Convert.ToDecimal(priceStr) / 100;

                        string key = item.ID + "{" + item.Format + "}";

                        if (ShopAllItems.ContainsKey(key))
                        {
                            if (item.ShopPrice != 0 && ShopAllItems[key].ShopPrice > item.ShopPrice)
                            {
                                ShopAllItems[key] = item;
                            }
                        }
                        else
                        {
                            ShopAllItems.Add(key, item);
                        }

                        CommonFun.WriteCSV("QLK/QL" + ticks + ".csv", item);
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Пример #3
0
        public void ReadOneItem(string url)
        {
            try
            {
                string content = request.HttpGet(url);

                int startIndex = content.IndexOf("<div class=\"prem-dtl-infomation\">");

                int endIndex = content.IndexOf("<div class=\"inf-r-wxhb\">");

                string mainStr = content.Substring(startIndex, endIndex - startIndex);

                MatchCollection ms = CommonFun.GetValues(mainStr, "<div class=\"dtl-inf-r\">", "</div>");

                if (!string.IsNullOrEmpty(ms[0].Value) && !ms[0].Value.Contains("注射"))
                {
                    ItemInfo info = new ItemInfo();

                    info.Name = ms[0].Value;

                    string idStr = ms[1].Value;

                    info.ID = string.IsNullOrEmpty(idStr) ? "" : idStr.Substring(0, idStr.IndexOf('\n'));

                    info.Created = ms[2].Value;

                    info.Format = CommonFun.GetValue(content, "规格:", "<");

                    info.Type = CommonFun.GetValue(content, "剂型:", "<");

                    info.ItemName = CommonFun.GetValue(content, "商品名称:", "<");

                    info.BrandName = info.ItemName.Split(' ')[0];

                    info.DrugType = GetDrugType(content);

                    string priceStr = CommonFun.GetValue(content, "salePrice : ", ",");

                    info.ShopPrice = string.IsNullOrEmpty(priceStr) ? 0 : Convert.ToDecimal(priceStr);

                    string key = info.ID + "{" + info.Format + "}";

                    SetMenuInfo(content, info);

                    SetMainInfo(content, info);

                    SetPicture(content, info);

                    if (ShopAllItems.ContainsKey(key))
                    {
                        if (info.ShopPrice != 0 && ShopAllItems[key].ShopPrice > info.ShopPrice)
                        {
                            ShopAllItems[key] = info;
                        }
                    }
                    else
                    {
                        ShopAllItems.Add(key, info);
                    }

                    // CommonFun.WriteCSV("360Kad.csv", info);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex + string.Format(url));
            }
        }
Пример #4
0
        /// <summary>
        /// 生成商城信息
        /// </summary>
        /// <param name="items"></param>
        private void CreateItemInfo(List <string> items)
        {
            string temp = null;

            try
            {
                Console.WriteLine("ItemsCount:{0}", items.Count);

                foreach (string item in items)
                {
                    temp = item;

                    ItemInfo        info = new ItemInfo();
                    MatchCollection ms   = CommonFun.GetValues(item, "value=\"", "\"");
                    info.Name = ms[0].Value;

                    if (info.Name.Contains("注射"))
                    {
                        continue;
                    }

                    info.Format = ms[1].Value + "/" + ms[3];
                    info.Format = info.Format.Replace("*", "x");
                    info.Format = info.Format.Replace("s", "片");
                    info.Format = info.Format.Replace("代", "袋");

                    info.Created = ms[4].Value;

                    info.SellType = CommonFun.GetValue(item, "【", "】");

                    if (info.SellType.Count() > 1)
                    {
                        info.SellType = CommonFun.GetValue(info.SellType, ">", "<");
                    }

                    info.Inventory = CommonFun.GetValue(item, "数量:", "<");
                    info.ID        = "国药准字" + CommonFun.GetValue(item, "批准文号:", "<");
                    info.ShopPrice = Convert.ToDecimal(CommonFun.GetValue(item, "价格:<span>", "元"));

                    string key = info.ID + "{" + info.Format + "}";

                    if (ShopAllItems.ContainsKey(key))
                    {
                        if (ShopAllItems[key].ShopPrice > info.ShopPrice)
                        {
                            ShopAllItems[key] = info;
                        }
                    }
                    else
                    {
                        ShopAllItems.Add(key, info);
                    }

                    // CommonFun.WriteCSV("商城信息.csv", info);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("content;{0}, error:{1}", temp, ex.ToString());
            }

            Console.WriteLine("ShopAllItemCount:{0}", ShopAllItems.Count);
        }
Пример #5
0
        public override void ReadAllItem()
        {
            Dictionary <string, string> itemIDAndPrices = new Dictionary <string, string>();

            string pageListUrl = "http://api.12yao.com/v1003/products/list?j={0}&p1=&r={1}&t=151306281";

            string itemUrl = "http://api.12yao.com/v1003/products/pharmacy_list?g=0&id={0}&t=151306508";

            int totalCount = menuList.Count;
            int curCount   = 0;

            foreach (string j in menuList.Keys)
            {
                try
                {
                    int r = 1;

                    string url = string.Format(pageListUrl, j, r);

                    string content = request.HttpGet(url);

                    JObject jo = (JObject)JsonConvert.DeserializeObject(content);

                    int totalPage = (int)Math.Ceiling(Convert.ToDouble(jo["d"]["k"]) / 20);

                    GetItemIDs(content, itemIDAndPrices);

                    for (r++; r <= totalPage; r++)
                    {
                        url = string.Format(pageListUrl, j, r);

                        content = request.HttpGet(url);

                        GetItemIDs(content, itemIDAndPrices);

                        Console.WriteLine("TotalPage:{0}, curPage:{1}", totalPage, r);
                    }

                    Console.WriteLine("TotalCount:{0}, CurCount:{1}", totalCount, ++curCount);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("err:{0}, list:{1}", ex.ToString(), j);
                }
            }

            foreach (string id in itemIDAndPrices.Keys)
            {
                string url = string.Format(itemUrl, id);

                string content = request.HttpGet(url);

                BaseItemInfo item = GetItemInfo(content, itemIDAndPrices[id]);

                if (item != null)
                {
                    string key = item.ID + item.Format + item.Created;
                    if (!ShopAllItems.ContainsKey(key))
                    {
                        ShopAllItems.Add(key, item);
                    }
                    else if (ShopAllItems[key].PlatformPrice > item.PlatformPrice)
                    {
                        ShopAllItems[key].PlatformPrice = item.PlatformPrice;
                    }
                }
                else
                {
                    Console.WriteLine("Item is null,id:{0}", id);
                }
            }

            foreach (BaseItemInfo item in ShopAllItems.Values)
            {
                CommonFun.WriteCSV(fileName, item);
            }
        }