public void ReadAllItemUrl(string fileName)
        {
            string content = CommonFun.ReadCSV(fileName);

            if (string.IsNullOrEmpty(content))
            {
                string[] lines = content.Split('\r');

                foreach (string line in lines)
                {
                    allItemUrl.Add(line);
                }
            }
            else
            {
                Console.WriteLine("ReadAllItemUrl error" + fileName);
            }
        }
        protected Dictionary <string, BaseItemInfo> ReadXlsItems(string fileName)
        {
            Dictionary <string, BaseItemInfo> items = new Dictionary <string, BaseItemInfo>();

            try
            {
                DataTable data = CommonFun.ReadXLS(fileName);

                for (int row = 0; row < data.Rows.Count; row++)
                {
                    try
                    {
                        BaseItemInfo item = new BaseItemInfo();
                        item.ID       = data.Rows[row]["批准文号"].ToString();
                        item.Name     = (string)data.Rows[row]["通用名称"].ToString();
                        item.ItemName = data.Columns.Contains("商品名称") ? data.Rows[row]["商品名称"].ToString() : "";
                        item.Created  = (string)data.Rows[row]["生产厂家"].ToString();
                        item.Format   = (string)data.Rows[row]["包装规格"].ToString();
                        string priceStr = (string)data.Rows[row]["平台售价(最低价格)"].ToString();
                        item.ShopPrice     = string.IsNullOrEmpty(priceStr) ? 9999 : Convert.ToDecimal(priceStr);
                        item.PlatformPrice = item.ShopPrice;
                        item.Type          = data.Columns.Contains("剂型") ? (string)data.Rows[row]["剂型"].ToString() : "";
                        item.Inventory     = (string)data.Rows[row]["库存"].ToString();
                        item.SellType      = (string)data.Rows[row]["出售方式(零或整)"].ToString();

                        string key = item.Name + item.Format + item.Created;
                        if (!items.ContainsKey(key))
                        {
                            items.Add(key, item);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(items);
        }
Exemple #3
0
        private void SetPicture(string content, ItemInfo info)
        {
            string prictureUrlStr = CommonFun.GetValue(content, "<div class=\"minPicScrolldiv\">", "</div>");

            MatchCollection ms = CommonFun.GetValues(prictureUrlStr, "src=\"", "\"");

            info.PicturePath = @"Picture/" + info.Name.Replace('.', '_').Replace('*', '_').Replace(':', '_').Replace(" ", "") + "/" + info.Format.Replace('.', '_').Replace('*', '_').Replace(':', '_').Replace(" ", "") + "/";

            int pictureCount = 0;

            //foreach (Match url in ms)
            //{
            //    Image image = request.HttpGetPicture(url.Value);

            //    CommonFun.SavePicture(image, info.PicturePath + pictureCount++ + ".jpg");
            //}


            info.PicturePath = string.Format("=HYPERLINK(\"{0}\")", info.PicturePath);
        }
Exemple #4
0
        public override void ReadAllMenuURL()
        {
            string content = request.HttpGet("http://www.hyey.cn/Drug/DrugList.aspx", "fl=2&syz=14&ypmc=盐酸多巴酚丁胺注射液");

            int startIndex = content.IndexOf("item bo");

            int endIndex = content.LastIndexOf("</a></em>");

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

            MatchCollection ms = CommonFun.GetValues(content, "<em><a", "</a></em>");

            foreach (Match m in ms)
            {
                if (!m.Value.Contains("注射"))
                {
                    string value = CommonFun.GetValue(m.Value, "href=\"", "\"");

                    AllMenuUrl.Add(value);

                    // Console.WriteLine("value:{0}", value);
                }
            }
        }
Exemple #5
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);
        }
        private void CreateItemOtherInfo(object value)
        {
            string temp = null;

            try
            {
                string name = (string)value;

                if (name.Contains("注射"))
                {
                    return;
                }

                HttpRequest tempRequest = new HttpRequest();

                string url = string.Format("http://www.yaofangwang.com/search.html?keyword={0}", System.Web.HttpUtility.UrlEncode(name));

                string content = tempRequest.HttpGetPlatform(url);

                List <string> items = GetItemStr(content);

                foreach (string item in items)
                {
                    bool result = false;
                    do
                    {
                        try
                        {
                            temp = item;

                            ItemInfo info = new ItemInfo();

                            info.Format  = CommonFun.GetValue(item, "规格:", "<");
                            info.Created = CommonFun.GetValue(item, "生产厂家:", "<");
                            //库存
                            info.ID = CommonFun.GetValue(item, "批准文号:", "<");

                            string priceStr = CommonFun.GetValue(item, "¥", "<");

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

                            content = tempRequest.HttpGetPlatform(CommonFun.GetValue(item, "<a target=\"_blank\" href=\"", "\""));

                            int startIndex = content.IndexOf("<div class=\"share clearfix\">");

                            int endIndx = content.IndexOf("id=\"priceA\">");

                            content = content.Substring(startIndex, endIndx - startIndex);

                            info.ViewCount = CommonFun.GetValue(content, "<dt>最近浏览</dt><dd class=\"w1\">", "次");

                            info.Name = CommonFun.GetValue(content, "<dd class=\"w2 l\"><strong>", "<");

                            MatchCollection ms = CommonFun.GetValues(content, "<dd class=\"w3 l\">", "</");

                            info.Type = ms[1].Value;

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

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

                            CommonFun.WriteCSV("平台信息.csv", info);
                            result = true;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.ToString());
                        }
                    } while (!result);
                }

                Console.WriteLine("finishName;{0}, finishCoutn:{1}, totalCount:{2}", name, ++finishCount, toltalCount);

                if (finishCount == toltalCount)
                {
                    Console.WriteLine("Finished !!!!!!!!!!!!!!!!!");
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("content;{0}, error:{1}", temp, ex.ToString());
            }
        }
Exemple #7
0
        public static string FormatStr(string format, string name)
        {
            try
            {
                if (format.Contains('+'))
                {
                }

                if ((format.Contains('(') && format.Contains(')')) || (format.Contains('(') && format.Contains(')')))
                {
                    if ((format.Contains('(') && format.Contains(')')))
                    {
                        format = format.Substring(0, format.IndexOf('(')) + format.Substring(format.IndexOf(')') + 1, format.Length - format.IndexOf(')') - 1);
                    }
                    else
                    {
                        format = format.Substring(0, format.IndexOf('(')) + format.Substring(format.IndexOf(')') + 1, format.Length - format.IndexOf(')') - 1);
                    }
                }

                format = format.Replace("/盒/盒", "/盒");
                format = format.Replace("(", "");
                format = format.Replace(")", "");
                format = format.Replace("(", "");
                format = format.Replace(")", "");
                format = format.Replace("毫克", "mg");
                format = format.Replace('克', 'g');
                format = format.Replace('G', 'g');
                format = format.Replace('*', 'x');
                format = format.Replace('×', 'x');
                format = format.Replace(':', ':');
                format = format.Replace('∶', ':');
                format = format.Replace("..", ".");
                format = format.Replace("毫升", "ml");
                format = format.Replace("丸", "粒");
                format = format.Replace("张", "贴");
                format = format.Replace("瓶/盒", "/瓶");
                format = format.Replace("g/袋", "g");
                format = format.Replace("万单位", "IU");

                if (!string.IsNullOrEmpty(name))
                {
                    if (name.Contains("片"))
                    {
                        format = format.Replace('s', '片');
                        format = format.Replace('粒', '片');
                    }
                    else
                    {
                        format = format.Replace('s', '粒');
                    }
                }
                if (format.Contains("mg") || format.Contains("g"))
                {
                    string[] values = format.Split('x');

                    if (values[0].Contains(':'))
                    {
                        values[0] = values[0].Substring(0, values[0].IndexOf(':'));
                    }

                    decimal value1 = format.Contains("mg") ? (Convert.ToDecimal(CommonFun.GetNum(values[0])) / 1000) : Convert.ToDecimal(CommonFun.GetNum(values[0]));

                    format = "";

                    format += value1 + "g" + "x";

                    for (int i = 1; i < values.Length; i++)
                    {
                        format += values[i] + "x";
                    }

                    format = format.Substring(0, format.LastIndexOf('x'));
                }

                if (format.Contains("片") && format.Contains("板"))
                {
                    return(SumFormat(format, "片", "板"));
                }
                else if (format.Contains("粒") && format.Contains("板"))
                {
                    return(SumFormat(format, "粒", "板"));
                }
                else if (format.Contains("粒") && format.Contains("瓶"))
                {
                    return(SumFormat(format, "粒", "瓶"));
                }
                else if (format.Contains("片") && format.Contains("瓶"))
                {
                    return(SumFormat(format, "片", "瓶"));
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(format + ex.ToString());
            }
            return(format);
        }
Exemple #8
0
        public static bool IsSameFormat(string format1, string format2, string name1, string name2)
        {
            string pFormat = FormatStr(format1, name1);

            string sFormat = FormatStr(format2, name2);

            string[] array1 = pFormat.Split('/');

            string[] array2 = sFormat.Split('/');

            try
            {
                if (array1[0].Contains('x'))
                {
                    string[] values = array1[0].Split('x');
                    decimal  format = 1;
                    foreach (string value in values)
                    {
                        if (value.Contains(":"))
                        {
                            string[] sValues = value.Split(':');
                            foreach (string sValue in sValues)
                            {
                                string num = CommonFun.GetNum(sValue);
                                format *= (string.IsNullOrEmpty(num) ? 1 : Convert.ToDecimal(num));
                            }
                        }
                        else
                        {
                            string num = CommonFun.GetNum(value);
                            format *= (string.IsNullOrEmpty(num) ? 1 : Convert.ToDecimal(num));
                        }
                    }
                    string info = Regex.Replace(values[0], @"[\d.\d]", "");
                    if (string.IsNullOrEmpty(info) && !string.IsNullOrEmpty(values[1]))
                    {
                        info = Regex.Replace(values[1], @"[\d.\d]", "");
                    }

                    array1[0] = format + info;
                }

                if (array2[0].Contains('x'))
                {
                    string[] values = array2[0].Split('x');
                    decimal  format = 1;
                    foreach (string value in values)
                    {
                        if (value.Contains(":"))
                        {
                            string[] sValues = value.Split(':');
                            foreach (string sValue in sValues)
                            {
                                string num = CommonFun.GetNum(sValue);
                                format *= (string.IsNullOrEmpty(num) ? 1 : Convert.ToDecimal(num));
                            }
                        }
                        else
                        {
                            string num = CommonFun.GetNum(value);
                            format *= (string.IsNullOrEmpty(num) ? 1 : Convert.ToDecimal(num));
                        }
                    }
                    string info = Regex.Replace(values[0], @"[\d.\d]", "");
                    array2[0] = format + info;
                }

                if (array1.Length == 2 && array2.Length == 2)
                {
                    if (array1[1].Contains('x'))
                    {
                        string[] values = array1[1].Split('x');
                        string   info   = Regex.Replace(array1[0], @"[\d.\d]", "");
                        array1[0] = Convert.ToDecimal(CommonFun.GetNum(values[1])) * Convert.ToDecimal(CommonFun.GetNum(array1[0])) + info;
                    }

                    if (array2[1].Contains('x'))
                    {
                        string[] values = array2[1].Split('x');
                        string   info   = Regex.Replace(array2[0], @"[\d.\d]", "");
                        array2[0] = Convert.ToDecimal(CommonFun.GetNum(values[1])) * Convert.ToDecimal(CommonFun.GetNum(array2[0])) + info;
                    }

                    if (array1[0] == array2[0])
                    {
                        return(true);
                    }
                }
                else
                {
                    if (array1[0] == array2[0])
                    {
                        return(true);
                    }
                    else
                    {
                        string[] value1 = array1[0].Split('x');
                        string[] value2 = array2[0].Split('x');

                        if (value1.Length != value2.Length)
                        {
                            if (value1[0] == value2[0])
                            {
                                return(true);
                            }
                            //List<decimal> lValue1 = new List<decimal>();
                            //foreach(string value in value1)
                            //{
                            //    lValue1.Add(Convert.ToDecimal(CommonFun.GetNum(value)));
                            //}

                            //foreach (string value in value2)
                            //{
                            //    if(lValue1.Contains(Convert.ToDecimal(CommonFun.GetNum(value))))
                            //    {
                            //        return true;
                            //    }
                            //}
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(false);
        }
Exemple #9
0
        private static string SumFormat(string format, string key1, string key2)
        {
            if (format.Contains(key1) && format.Contains(key2))
            {
                string[] array1 = format.Split('/');

                if (array1.Length == 2)
                {
                    string[] array = array1[0].Split('x');

                    if (array.Length == 3)
                    {
                        decimal value = Convert.ToDecimal(CommonFun.GetNum(array[1])) * Convert.ToDecimal(CommonFun.GetNum(array[2]));

                        return(array[0] + "x" + value + key1 + "/" + array1[1]);
                    }
                }
                else
                {
                    string[] array = format.Split('x');
                    if (array.Length == 3)
                    {
                        decimal value = Convert.ToDecimal(CommonFun.GetNum(array[1])) * Convert.ToDecimal(CommonFun.GetNum(array[2]));

                        return(array[0] + "x" + value + key1);
                    }
                }
            }

            return(format);
        }
        public void Compare(string pFileName, string sFileName, string createDir, bool isload = false)
        {
            ReadPlatFormWebPageValue flatform = new ReadPlatFormWebPageValue();
            BaseReadWebPage          platform = new BaseReadWebPage();
            BaseReadWebPage          shop     = new BaseReadWebPage();

            if (!string.IsNullOrEmpty(pFileName))
            {
                platform.ReadBaseItemInfo(pFileName, true);
            }


            shop.ReadBaseItemInfo(sFileName, true);

            foreach (BaseItemInfo item in shop.ShopAllItems.Values)
            {
                bool   isEixst  = false;
                string itemName = item.Name;

                if (item.Name.Contains("】"))
                {
                    int itemNameIndex = item.Name.LastIndexOf("】") + 1;
                    itemName = item.Name.Substring(itemNameIndex, item.Name.Length - itemNameIndex);
                }

                if (itemName.Contains("("))
                {
                    int itemNameIndex = itemName.IndexOf('(');

                    itemName = itemName.Substring(0, itemNameIndex);
                }

                foreach (BaseItemInfo platformItem in platform.ShopAllItems.Values)
                {
                    bool isSame = false;
                    if (!string.IsNullOrEmpty(item.ID) && !string.IsNullOrEmpty(platformItem.ID))
                    {
                        if (item.ID.Trim() == platformItem.ID.Trim())
                        {
                            isSame = true;
                        }
                    }


                    if (isSame || (itemName == platformItem.Name && item.Created == platformItem.Created))
                    {
                        if (CommonFun.IsSameFormat(platformItem.Format, item.Format, platformItem.Name, item.Name))
                        {
                            isEixst = true;
                            if (ComparePrice(platformItem, item))
                            {
                                break;
                            }
                        }
                    }
                }

                if (!isEixst && isload)
                {
                    List <BaseItemInfo> seachItems = flatform.SeachInfoByID(item.ID);

                    Dictionary <string, BaseItemInfo> saveInfos = new Dictionary <string, BaseItemInfo>();

                    foreach (BaseItemInfo info in seachItems)
                    {
                        string key = info.Name + info.Format + info.Created;

                        if (!platform.ShopAllItems.ContainsKey(key))
                        {
                            if (item.ID == info.ID || (itemName == info.Name && item.Created == info.Created))
                            {
                                if (CommonFun.IsSameFormat(info.Format, item.Format, info.Name, item.Name))
                                {
                                    isEixst = true;
                                    ComparePrice(info, item);
                                }
                            }

                            platform.ShopAllItems.Add(key, info);
                            saveInfos.Add(key, info);
                        }
                        else if (platform.ShopAllItems[key].ShopSelaPrice > info.ShopSelaPrice)
                        {
                            if (item.ID == info.ID || (itemName == info.Name && item.Created == info.Created))
                            {
                                if (CommonFun.IsSameFormat(info.Format, item.Format, info.Name, item.Name))
                                {
                                    isEixst = true;
                                    ComparePrice(info, item);
                                }
                            }

                            platform.ShopAllItems[key] = info;
                            saveInfos[key]             = info;
                        }
                    }

                    foreach (BaseItemInfo saveInfo in saveInfos.Values)
                    {
                        string name = string.IsNullOrEmpty(pFileName) ? "Platform/Platform" + ticks + ".csv" : pFileName;
                        CommonFun.WriteCSV(name, saveInfo);
                    }
                }

                if (!isEixst)
                {
                    CommonFun.WriteCSV(createDir + "/NotIsEixst" + ticks + ".csv", item);
                }
            }
        }
        /// <summary>
        /// 对比价格(在线数据)
        /// </summary>
        public void OnlineComparePrice()
        {
            ReadPlatFormWebPageValue flatform = new ReadPlatFormWebPageValue();

            Dictionary <string, BaseItemInfo> platItems = new Dictionary <string, BaseItemInfo>();

            Dictionary <string, List <BaseItemInfo> > seachItems = new Dictionary <string, List <BaseItemInfo> >();

            Dictionary <string, string> seachedItemName = new Dictionary <string, string>();

            foreach (BaseItemInfo item in ShopAllItems.Values)
            {
                string key = item.Name + item.Format + item.Created;

                //查找该商品
                if (!seachedItemName.ContainsKey(item.Name))
                {
                    seachedItemName.Add(item.Name, item.Name);

                    List <BaseItemInfo> item_list = flatform.SeachInfoByID(item.Name);

                    Dictionary <string, BaseItemInfo> minPricItems = new Dictionary <string, BaseItemInfo>();


                    foreach (BaseItemInfo sItem in item_list)
                    {
                        string sItemKey = sItem.Name + sItem.Format + sItem.Created;

                        if (!platItems.ContainsKey(sItemKey))
                        {
                            platItems.Add(sItemKey, sItem);
                            minPricItems.Add(sItemKey, sItem);
                        }
                        else if (platItems[sItemKey].ShopSelaPrice > sItem.ShopSelaPrice)
                        {
                            platItems[sItemKey]    = sItem;
                            minPricItems[sItemKey] = sItem;
                        }
                    }

                    seachItems.Add(item.Name, minPricItems.Values.ToList());
                }

                //对比价格
                if (seachItems.ContainsKey(item.Name))
                {
                    List <BaseItemInfo> compareItems = seachItems[item.Name];
                    bool isExist = false;
                    foreach (BaseItemInfo compareItem in compareItems)
                    {
                        if (item.Created == compareItem.Created)
                        {
                            if (CommonFun.IsSameFormat(item.Format, compareItem.Format, item.Name, compareItem.Name))
                            {
                                isExist = true;
                                //价格对比
                                if (item.ShopPrice > 0 && item.ShopPrice * (decimal)0.75 >= compareItem.ShopSelaPrice)
                                {
                                    //浏览量对比
                                    if (!string.IsNullOrEmpty(compareItem.ViewCount) && Convert.ToInt32(compareItem.ViewCount) >= 500)
                                    {
                                        item.ID            = compareItem.ID;
                                        item.ShopSelaPrice = compareItem.ShopSelaPrice;
                                        item.Type          = compareItem.Type;
                                        item.ViewCount     = compareItem.ViewCount;

                                        CommonFun.WriteCSV("25%" + ticks + ".csv", item);
                                    }
                                }
                                break;
                            }
                        }
                    }
                    if (!isExist)
                    {
                        CommonFun.WriteCSV("YaoTu/NoFormat" + ticks + ".csv", item);
                    }
                }
                else
                {
                    CommonFun.WriteCSV("YaoTu/NotExist" + ticks + ".csv", item);
                }
            }

            foreach (BaseItemInfo item in platItems.Values)
            {
                CommonFun.WriteCSV("YaoTu/Plateform" + ticks + ".csv", item);
            }
        }
 public void WriteItem(BaseItemInfo item, string fileName)
 {
     CommonFun.WriteCSV(fileName, item);
 }
 public void WriteErrorUrl(string url, string fileName)
 {
     CommonFun.WriteUrlCSV(fileName, url);
 }
        public void ReadBaseItemInfo(string fileName, bool isBaseItemInfo)
        {
            //DataTable data = CommonFun.ReadXLS(fileName);
            string content = CommonFun.ReadCSV(fileName);

            if (!string.IsNullOrEmpty(content))
            {
                string[] lines = content.Split('\r');

                string[] menu = null;

                foreach (string line in lines)
                {
                    try
                    {
                        if (!line.Contains('\n'))
                        {
                            menu = line.Split(',');
                        }
                        else
                        {
                            string newLine = line;

                            MatchCollection ms = CommonFun.GetValues(newLine, "\"\"\"", "\"\"\"");

                            for (int i = 0; i < ms.Count; i++)
                            {
                                if (!string.IsNullOrEmpty(ms[i].Value))
                                {
                                    newLine = newLine.Replace(ms[i].Value, string.Format("{{0}}", i));
                                }
                            }

                            string[] infoStr = newLine.Split(',');

                            for (int i = 0; i < infoStr.Length; i++)
                            {
                                for (int j = 0; j < ms.Count; j++)
                                {
                                    infoStr[i] = infoStr[i].Replace(string.Format("{{0}}", j), ms[j].Value);
                                }
                            }

                            if (infoStr.Length > 1)
                            {
                                BaseItemInfo info = isBaseItemInfo ? new BaseItemInfo() : new ItemInfo();

                                string[] menuName = info.GetLogHeadLine().Split(',');

                                SetBaseItemInfo(info, infoStr, menu);

                                if (!isBaseItemInfo)
                                {
                                    SetItemInfo(info as ItemInfo, infoStr, menu);
                                }

                                string key = info.Name + info.Format + info.Created;

                                if (!shopAllItems.ContainsKey(key))
                                {
                                    shopAllItems.Add(key, info);
                                }
                                else if (shopAllItems[key].ShopPrice > info.ShopPrice)
                                {
                                    shopAllItems[key] = info;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
            }
            else
            {
                Console.WriteLine("ReadBaseItemInfo error" + fileName);
            }
        }
Exemple #15
0
        /// <summary>
        /// 获取所有商城数据
        /// </summary>
        public void ReadShopAllItem()
        {
            List <string> items = new List <string>();

            try
            {
                int count = 0;
                foreach (string url in AllMenuUrl)
                {
                    count++;
                    string content = request.HttpGet("http://www.hyey.cn" + url);

                    List <string> temp = new List <string>();

                    temp = GetItmeStr(content);

                    if (temp.Count > 0)
                    {
                        items.AddRange(temp);

                        string pageStr = CommonFun.GetValue(content, "<span id=\"lblTotalPageV\" style=\"border-color: #00a1fd;\">", "</span>");

                        if (string.IsNullOrEmpty(pageStr))
                        {
                            Console.WriteLine(pageStr);
                        }
                        else
                        {
                            int pageIndex = Convert.ToInt32(pageStr);

                            for (int i = 1; i < pageIndex; i++)
                            {
                                string postString = null;

                                string otherParam = GetOtherParam(temp);

                                postString = string.Format("__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE={0}&__EVENTVALIDATION={1}&TextBox1=&txtSelect=&HiddenField1=&hidd=&hiddLV=1&{2}btnNextV={3}&txtPageSizeV=&hidPageV=1", System.Web.HttpUtility.UrlEncode(GetParamValue(content, "__VIEWSTATE")), System.Web.HttpUtility.UrlEncode(GetParamValue(content, "__EVENTVALIDATION")), otherParam, "下一页");

                                content = request.HttpPost("http://www.hyey.cn" + url, postString);

                                temp = GetItmeStr(content);

                                items.AddRange(temp);
                            }
                        }

                        // Console.WriteLine(content);
                    }
                    else
                    {
                        Console.WriteLine(url);
                    }

                    Console.WriteLine("Count:{0}, tatalCount:{1}, URL:{2}", count, AllMenuUrl.Count, url);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            CreateItemInfo(items);
        }
Exemple #16
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));
            }
        }
Exemple #17
0
        private static void ComparePrice4(BaseItemInfo platformItem, BaseItemInfo info, string fileName)
        {
            if (info.ShopPrice * (decimal)1.25 <= platformItem.ShopSelaPrice)
            {
                info.ID            = platformItem.ID;
                info.PlatformPrice = platformItem.ShopPrice;
                info.ShopSelaPrice = platformItem.ShopSelaPrice;
                info.Sela          = platformItem.Sela;
                info.ViewCount     = platformItem.ViewCount;
                info.Type          = platformItem.Type;

                CommonFun.WriteCSV(fileName + "/25以上.csv", info);
            }
            else if (info.ShopPrice * (decimal)1.15 <= platformItem.ShopSelaPrice &&
                     info.ShopPrice * (decimal)1.25 > platformItem.ShopSelaPrice)
            {
                info.ID            = platformItem.ID;
                info.PlatformPrice = platformItem.ShopPrice;
                info.ShopSelaPrice = platformItem.ShopSelaPrice;
                info.Sela          = platformItem.Sela;
                info.ViewCount     = platformItem.ViewCount;
                info.Type          = platformItem.Type;

                CommonFun.WriteCSV(fileName + "/15-25.csv", info);
            }
            else if (info.ShopPrice * (decimal)1.05 <= platformItem.ShopSelaPrice &&
                     info.ShopPrice * (decimal)1.15 > platformItem.ShopSelaPrice)
            {
                info.ID            = platformItem.ID;
                info.PlatformPrice = platformItem.ShopPrice;
                info.ShopSelaPrice = platformItem.ShopSelaPrice;
                info.Sela          = platformItem.Sela;
                info.ViewCount     = platformItem.ViewCount;
                info.Type          = platformItem.Type;;

                CommonFun.WriteCSV(fileName + "/5-15.csv", info);
            }
            else if (info.ShopPrice <= platformItem.ShopSelaPrice &&
                     info.ShopPrice * (decimal)1.05 > platformItem.ShopSelaPrice)
            {
                info.ID            = platformItem.ID;
                info.PlatformPrice = platformItem.ShopPrice;
                info.ShopSelaPrice = platformItem.ShopSelaPrice;
                info.Sela          = platformItem.Sela;
                info.ViewCount     = platformItem.ViewCount;
                info.Type          = platformItem.Type;

                CommonFun.WriteCSV(fileName + "/0-5.csv", info);
            }
            else
            {
                info.ID            = platformItem.ID;
                info.PlatformPrice = platformItem.ShopPrice;
                info.ShopSelaPrice = platformItem.ShopSelaPrice;
                info.Sela          = platformItem.Sela;
                info.ViewCount     = platformItem.ViewCount;
                info.Type          = platformItem.Type;

                CommonFun.WriteCSV(fileName + "/0以下.csv", info);
            }
        }
Exemple #18
0
        private void SetMainInfo(string content, ItemInfo info)
        {
            string mainInfoStr = CommonFun.GetValue(content, "<ul class=\"instructions-ul\">", "</ul>");

            int index = mainInfoStr.IndexOf("见【");

            List <string> replacelist = new List <string>();

            int i = 0;

            while (index > 0)
            {
                string tempStr = mainInfoStr.Substring(index, mainInfoStr.Length - index);

                int end = tempStr.IndexOf("】");

                string replaceStr = mainInfoStr.Substring(index, end + 1);

                replacelist.Add(replaceStr);

                mainInfoStr = mainInfoStr.Replace(replaceStr, string.Format("{{0}}", i++));

                index = mainInfoStr.IndexOf("见【");
            }

            MatchCollection titles = CommonFun.GetValues(mainInfoStr, "【", "】");

            MatchCollection ms = CommonFun.GetValues(mainInfoStr, "】", "【");

            List <string> values = new List <string>();

            foreach (Match m in ms)
            {
                values.Add(m.Value);
            }
            int    startIndex = mainInfoStr.LastIndexOf("】");
            string lastValue  = mainInfoStr.Substring(startIndex + 1, mainInfoStr.Length - startIndex - 1);
            int    endIndex   = lastValue.IndexOf('<');

            lastValue = lastValue.Substring(0, endIndex);
            values.Add(lastValue);
            for (int j = 0; j < replacelist.Count; j++)
            {
                for (int m = 0; m < values.Count; m++)
                {
                    string value = string.Format("{{0}}", j);

                    if (values[m].Contains(value))
                    {
                        values[m] = values[m].Replace(value, replacelist[j]);
                        continue;
                    }
                }
            }

            if (ms.Count > 1)
            {
                int mIndex = GetIndex("成", titles);
                if (mIndex != -1)
                {
                    info.Basis = RemoveTag(values[mIndex]);
                }

                mIndex = GetIndex("性", titles);
                if (mIndex != -1)
                {
                    info.Character = RemoveTag(values[mIndex]);
                }

                mIndex = GetIndex("治", titles);
                mIndex = mIndex == -1 ? mIndex = GetIndex("适", titles) : mIndex;
                if (mIndex != -1)
                {
                    info.Function = RemoveTag(values[mIndex]);
                }

                mIndex = GetIndex("法", titles);
                if (mIndex != -1)
                {
                    info.Use = RemoveTag(values[mIndex]);
                }

                mIndex = GetIndex("良", titles);
                if (mIndex != -1)
                {
                    info.AdverseReaction = RemoveTag(values[mIndex]);
                }

                mIndex = GetIndex("禁", titles);
                if (mIndex != -1)
                {
                    info.Contraindication = RemoveTag(values[mIndex]);
                }

                mIndex = GetIndex("意", titles);
                if (mIndex != -1)
                {
                    info.NoticMatters = RemoveTag(values[mIndex]);
                }

                mIndex = GetIndex("贮", titles);
                if (mIndex != -1)
                {
                    info.SaveType = RemoveTag(values[mIndex]);
                }
            }
        }
Exemple #19
0
        /// <summary>
        /// 获取非数字部分
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        //public static string GetUnNum(string value)
        //{
        //    return Regex.Replace(value, @"[\d.\d]", "");
        //}

        public static double GetFormatValue(string format)
        {
            double result = 0;

            try
            {
                format = format.Replace("毫克", "mg");
                format = format.Replace('克', 'g');
                format = format.Replace('G', 'g');
                format = format.Replace('*', 'x');
                format = format.Replace('×', 'x');
                format = format.Replace(':', ':');
                format = format.Replace('∶', ':');
                format = format.Replace("..", ".");
                format = format.Replace("毫升", "ml");

                List <string> valueList = new List <string>();

                string[] aFormat = format.Split('/');

                foreach (string iformat in aFormat)
                {
                    if (iformat.Contains('x'))
                    {
                        string[] aFormat1 = iformat.Split('x');

                        foreach (string iformat1 in aFormat1)
                        {
                            if (iformat1.Contains(':'))
                            {
                                valueList.AddRange(iformat1.Split(':'));
                            }
                            else
                            {
                                valueList.Add(iformat1);
                            }
                        }
                    }
                    else
                    {
                        valueList.Add(iformat);
                    }
                }

                foreach (string value in valueList)
                {
                    string numStr = CommonFun.GetNum(value);
                    double num    = string.IsNullOrEmpty(numStr) ? 1 : Convert.ToDouble(numStr);

                    if (result == 0)
                    {
                        result = num * 100000;
                    }
                    else
                    {
                        result *= num;
                    }
                }

                if (format.Contains("mg"))
                {
                    result /= 1000;
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(result);
        }