/// <summary> /// 是否可以接 /// </summary> /// <returns></returns> public bool CanTake(string content, Http.HttpRequest http) { string infoStr = CommonFun.GetValue(content, "<tr>", "</tr>"); MatchCollection tdMs = CommonFun.GetValues(infoStr, "<td>", "</td>"); string orderNO = CommonFun.GetValue(infoStr, "<td class=\"tablenow\">", "</td>"); bool result = false; MatchCollection ms = CommonFun.GetValues(content, "<div class=\"tkzds\">", "</div>"); string format = ms[0].Value; string id = ms[1].Value; string key = id + format; //是否TK平台的单 if (orderNO.StartsWith("TK") && !IsSelfOrder(content)) { string drs = tdMs[5].Value; //不是同城 if (!drs.Contains("长沙")) { BaseItemInfo item = items.ContainsKey(key) ? items[key] : null; //在线支付 if (infoStr.Contains("在线支付") || (infoStr.Contains("货到付款") && item != null && item.Type == "201")) { string msg = CommonFun.GetValue(content, "<li>买家留言:<span>", "</span></li>"); string remark = CommonFun.GetValue(content, "<li>平台备注:<span>", "</span></li>"); //无需发票 if (!msg.Contains("发票") && !remark.Contains("发票")) { //MatchCollection ms = CommonFun.GetValues(content, "<div class=\"tkzds\">", "</div>"); //单品 if (ms.Count == 5) { //ms = CommonFun.GetValues(content, "span1 xiatiaomar\">", "</div>"); decimal price = Convert.ToDecimal(ms[2].Value); //价格合理 if (items.ContainsKey(key)) { if (true || items[key].PlatformPrice <= price) { result = true; } else { Console.WriteLine("Price info orderPrice:{0}, sellPrice:{1}", price, items[key].PlatformPrice); } } } } } } } return(result); }
private List <BaseItemInfo> GetSomeItem(string content) { List <BaseItemInfo> items = new List <BaseItemInfo>(); if (!string.IsNullOrEmpty(content)) { MatchCollection ms = CommonFun.GetValues(content, "<row>", "</row>"); foreach (Match m in ms) { try { BaseItemInfo item = new BaseItemInfo(); item.ViewCount = CommonFun.GetValue(m.Value, "<ARTID>", "</ARTID>"); item.Name = CommonFun.GetValue(m.Value, "<NAME>", "</NAME>"); item.Format = CommonFun.GetValue(m.Value, "<SPEC>", "</SPEC>"); item.Created = CommonFun.GetValue(m.Value, "<FACTORY>", "</FACTORY>"); item.ID = CommonFun.GetValue(m.Value, "<FILENO>", "</FILENO>"); string priceStr = CommonFun.GetValue(m.Value, "<PRICE>", "</PRICE>"); item.PlatformPrice = string.IsNullOrEmpty(priceStr) ? 0 : Convert.ToDecimal(priceStr); item.Type = CommonFun.GetValue(m.Value, "<MEDIATYPENAME>", "</MEDIATYPENAME>"); items.Add(item); AddItme(item, "HA/HA" + ticks + ".csv"); } catch (Exception ex) { Console.WriteLine(ex); } } } return(items); }
/// <summary> /// 上架新物品 /// </summary> /// <param name="id"></param> /// <returns></returns> public bool UpNewItem(BaseItemInfo item, Http.HttpRequest http) { if (item.ShopPrice < 5) { return(false); } //find string findUrl = "https://admin.tkyfw.com/Goods/findExp"; string findPostData = "store_id=34"; http.HttpPost(findUrl, findPostData); //findApp string findAppUrl = "https://admin.tkyfw.com/Goods/findAppNum"; string findAppPostData = string.Format("appNum:{0}", item.ID); http.HttpPost(findAppUrl, findAppPostData); string url = string.Format("https://admin.tkyfw.com/Goods/complateInfo?cat_first=&cat_second=&cat_third=&approval_number={0}", item.ID); string upNewItemUrl = "https://admin.tkyfw.com/Goods/findRepeatCheck"; string checkUrl = "https://admin.tkyfw.com/Goods/checkGoods"; string content = http.HttpGet(url); MatchCollection ms = CommonFun.GetValues(content, "gxtj_ul", "</li>"); foreach (Match m in ms) { string fromat = CommonFun.GetValue(m.Value, "<span>", "<span>"); fromat = CommonFun.FormatStr(fromat, item.Name); if (fromat == item.Format) { string boxStr = CommonFun.GetValue(m.Value, "\"checkbox\"", "/>"); string value = CommonFun.GetValue(boxStr, "value=\"", "\""); string result = http.HttpPost(upNewItemUrl, string.Format("value_arr={0}{1}", value, HttpUtility.UrlEncode(","))); result = CommonFun.GetValue(result, ":", "}"); if (result == "2") { CommonFun.WriteCSV("TKAdmin/UpNew" + fileName + ".csv", item); http.HttpPost(checkUrl, "", url, "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8", null); Console.WriteLine("UpNewItem,name:{0}, id:{1}, fromat:{2}", item.Name, item.ID, item.Format); } Thread.Sleep(random.Next(3, 6) * 1000); // UpdatePrice(item, http); } } return(true); }
public override void ReadAllMenuURL() { try { string url = "http://ad.dabai.7lk.com/findMedication/patCategories"; string postData = "doctorId=321967&userId=321967&token=9d571f1dc32cadf0ea38"; string content = request.HttpPost(url, postData); MatchCollection ms = CommonFun.GetValues(content, "\"children\":", "\"sortable\":"); foreach (Match m in ms) { MatchCollection mMs = CommonFun.GetValues(m.Value, "{", "}"); foreach (Match mM in mMs) { string pMenuName = CommonFun.GetValue(mM.Value, "\"parent\":\"", "\""); string sMenuName = CommonFun.GetValue(mM.Value, "\"title\":\"", "\""); Console.WriteLine("pMenuName:{0}, sMenuName:{1}", pMenuName, sMenuName); string menuData = string.Format("doctorId=321967&firTitle={0}&orderBy=default&secTitle={1}&userId=321967&token=9d571f1dc32cadf0ea38", HttpUtility.UrlEncode(pMenuName), HttpUtility.UrlEncode(sMenuName)); if (!AllMenuUrl.Contains(menuData)) { AllMenuUrl.Add(menuData); } } } } catch (Exception ex) { Console.WriteLine(ex); } }
/// <summary> /// 获取所有数据 /// </summary> public void GetAllItem() { login(); string url = "http://58.20.39.35:9090/powerweb/art/manage/gridArtOfQuery.action"; string content = request.HttpPost(url, null); string totalData = CommonFun.GetValue(content, "<rows><results>", "</results>"); double totalRows = Convert.ToDouble(totalData); int limit = 20 * 10; int totalPage = (int)Math.Ceiling(totalRows / limit); string postData = "start={0}&limit={1}&classId=&name=&factory=&ArtClassQuery_combo_id=&f_t_scm_article.spec=&f_t_scm_article.isonline%5EEQ="; for (int i = 0; i < totalPage; i++) { content = request.HttpPost(url, string.Format(postData, i * limit, limit)); List <BaseItemInfo> items = GetSomeItem(content); } }
private void GetOnePageItem(string content) { if (!string.IsNullOrEmpty(content)) { content = CommonFun.GetValue(content, "<div class=\"prod-list\">", "<div class=\"page mt20 mb130 clearfix\">"); GetOnePageBaseItemInfo(content); } }
/// <summary> /// 修改所有在售物品的价格 /// </summary> /// <returns></returns> public bool UpdateAllSellingItemPrice(string itemStr, GetWebPageDate.Http.HttpRequest http, decimal upParam = 1) { itemStr = itemStr.Replace('\n', ' '); itemStr = itemStr.Replace('\t', ' '); MatchCollection ms = CommonFun.GetValues(itemStr, "<div class=\"tkprolistbox\">", "修改"); foreach (Match m in ms) { ItemInfo item = GetOneItem(m.Value); string tag = CommonFun.GetValue(m.Value, "promotionEd=\"", "\""); decimal price = GetPlatformPrice(item.ID, item.Format, http); string info = ""; if (item.Type != "333" && price != decimal.MaxValue && item.PlatformPrice != price) { info = UpdatePrice(http, price * upParam, item.ViewCount, item.Type, item.Inventory); Thread.Sleep(random.Next(3, 6) * 1000); if (info != "1") { string priceStr = CommonFun.GetValue(info, ":\"", "\""); price = 0; try { price = Convert.ToDecimal(priceStr); if (price != 1) { price = (decimal)((double)price - 0.01); } else { price = GetItemPrice(item); } } catch (Exception ex) { Console.WriteLine(ex); } if (price != item.PlatformPrice) { UpdatePrice(http, price, item.ViewCount, tag, item.Inventory); } } } item.ShopPrice = price; CommonFun.WriteCSV("TKAdmin/TKAdmin" + fileName + ".csv", item); } return(true); }
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); } }
/// <summary> /// 接单处理 /// </summary> /// <param name="item"></param> /// <param name="http"></param> public void ProcessOrder(string item, Http.HttpRequest http) { if (CanTake(item, http)) { string id = CommonFun.GetValue(item, "rel=\"", "\""); if (!orderList.ContainsKey(id) && TakeOrder(id, http)) { orderList.Add(id, id); Console.WriteLine("Take Order !!!!!!!!!!!!!!!!!!"); } } }
/// <summary> /// 获取在售列表 /// </summary> /// <param name="http"></param> /// <returns></returns> public Dictionary <string, BaseItemInfo> GetSellingItem(Http.HttpRequest http) { Dictionary <string, BaseItemInfo> items = new Dictionary <string, BaseItemInfo>(); string url = "https://admin.tkyfw.com/Goods/throughAudit?/Goods/throughAudit=&status=1&state=1"; string content = http.HttpGet(url); string itemStr = CommonFun.GetValue(content, "<form name=\"form\" method=\"post\">", "</form>"); List <BaseItemInfo> temp = GetOnePageItems(itemStr); string pageStr = CommonFun.GetValue(content, "下一页", "><span>末页</span>"); pageStr = CommonFun.GetValue(pageStr, "&p=", "\""); pageStr = pageStr.Substring(pageStr.LastIndexOf("=") + 1); int totalPage = 0; if (!string.IsNullOrEmpty(pageStr)) { totalPage = Convert.ToInt32(pageStr); } for (int i = 2; i <= totalPage; i++) { content = http.HttpGet("https://admin.tkyfw.com/Goods/throughAudit?/Goods/throughAudit=&status=1&state=1&p=" + i); itemStr = CommonFun.GetValue(content, "<form name=\"form\" method=\"post\">", "</form>"); temp.AddRange(GetOnePageItems(itemStr)); Console.WriteLine("{0}:GetSelling totalPage:{1}, curPage{2}.....", DateTime.Now, totalPage, i); } foreach (BaseItemInfo item in temp) { string key = item.ID + item.Format; if (!items.ContainsKey(key)) { items.Add(key, item); } else { Console.WriteLine("Error, Same Itme key:{0}", key); } } return(items); }
private void GetOnePageBaseItemInfo(string content) { MatchCollection ms = CommonFun.GetValues(content, "<div class=\"desc\">", "<div class=\"other\">"); foreach (Match m in ms) { if (m.Value.Contains("noprice")) { return; } string priceStr = CommonFun.GetValue(m.Value, "</small>", "</span>"); if (string.IsNullOrEmpty(priceStr)) { Console.WriteLine("Login failed!!!!"); request.Cookie = "__jsluid=00722fe4a2305a1f7e6e44e846a302ce; ASP.NET_SessionId=nmfxaoaonht2wzmiafye2w4v; Hm_lvt_3f534012f862ad7faa732b5b0655ce2f=1514443356; historysearch=; Hm_lpvt_3f534012f862ad7faa732b5b0655ce2f=1514508794; YaoTuWang_Passport_Identity=9937796DFDBDE9A6A8AED4D5CF64EA4C22E6DA8F1256977C5DDB6BE83BA2792836A2A6441BE475E64955CB954B8A3C9BB962787AB25BA4E7E92EB98327D6A27934100ADE884D0F28E4D4DC2D60157EFCEA7568AFE2B3E7F059A623B3EE22F4024587087B0E98014BFD4E6AFEBA9D49A55B8B8335492218875C700F2DCBEC637CED603E8A15396800BC68A7A867559AEB744195D1"; return; } string name = CommonFun.GetValue(m.Value, "\">", "</a>"); if (name.Contains("注射")) { return; } else { BaseItemInfo info = new BaseItemInfo(); string[] nameArray = name.Split(' '); if (nameArray.Length > 1) { info.Name = nameArray[1]; } else { info.Name = nameArray[0]; } MatchCollection msFormatAndCreated = CommonFun.GetValues(m.Value, "<div class=\"h1\">", "</div>"); info.Format = msFormatAndCreated[1].Value; info.Created = msFormatAndCreated[2].Value; info.PlatformPrice = Convert.ToDecimal(priceStr); AddItme(info, "YaoTu/YaoTu" + ticks + ".csv"); } } }
public override void ReadAllItem() { List <string> itemUrl = new List <string>(); int totalCount = AllMenuUrl.Count; int curCount = 0; foreach (string menuUrl in AllMenuUrl) { try { string content = request.HttpGet(menuUrl); string totalPage = CommonFun.GetValue(content, "</span><span>/</span><span>", "</span>"); GetOnePageItem(content); string pageUrl = menuUrl.Substring(0, menuUrl.LastIndexOf('.')); if (!string.IsNullOrEmpty(totalPage)) { int total = Convert.ToInt32(totalPage); for (int i = 2; i <= total; i++) { if (pageUrl == "http://www.yaofangwang.cn/product-35539" && i >= 10) { break; } string url = string.Format("{0}-p{1}.html", pageUrl, i); content = request.HttpGet(url); GetOnePageItem(content); Console.WriteLine("TotalPage:{0}, CurCount:{1}", total, i); } } } catch (Exception ex) { Console.WriteLine(menuUrl); Console.WriteLine(ex.ToString()); } Console.WriteLine("TotalCount:{0}, CurCount:{1}", totalCount, ++curCount); } }
/// <summary> /// 获取下架列表 /// </summary> /// <param name="cookie"></param> /// <returns></returns> public bool GetDownListItem(CookieCollection cookie) { GetWebPageDate.Http.HttpRequest http = new GetWebPageDate.Http.HttpRequest(); string url = "https://admin.tkyfw.com/Goods/throughAudit?/Goods/throughAudit=&status=1&state=2"; http.Cookie = "acw_tc=AQAAAMj+8lkEeQUA3eT4OlKCFpqJmk95; Qs_lvt_150743=1509785002%2C1510643909; PHPSESSID=0cv28td420q4ii7ult49qm4111; sellerCooke=think%3A%7B%22sellerName%22%3A%22hankang%22%2C%22sellerStoreName%22%3A%22%25E9%2595%25BF%25E6%25B2%2599%25E5%258E%25BF001%25E5%25BA%2597%22%7D; Qs_pv_150743=3457133030228596700%2C2642740307105821700%2C2882295116553261000%2C1172614365052146400%2C979891720064693100; Hm_lvt_ed70f863f631ecaac146592025767ed8=1509785002,1510643909; Hm_lpvt_ed70f863f631ecaac146592025767ed8=1510645265; nTalk_CACHE_DATA={uid:kf_9335_ISME9754_guestTEMP1758-0E75-6A,tid:1510643909116098}; NTKF_T2D_CLIENTID=guestTEMP1758-0E75-6A74-9EB9-8632DF7CEB19; Hm_lvt_3ad2c5e8712b25159b989a93a9927632=1510644101; Hm_lpvt_3ad2c5e8712b25159b989a93a9927632=1510645266; Hm_lvt_7203bc79de07054ef3770e27e8ca9068=1509780503,1509934350,1510060776,1510543588; Hm_lpvt_7203bc79de07054ef3770e27e8ca9068=1510647168"; string content = http.HttpGet(url); string itemStr = CommonFun.GetValue(content, "<form name=\"form\" method=\"post\">", "</form>"); MatchCollection ms = CommonFun.GetValues(itemStr, "<div class=\"white-box table-box\">", "<div class=\"span2 operationone\">"); foreach (Match m in ms) { CommonFun.WriteCSV("TKAdmin/down.csv", GetOneItem(m.Value)); } string pageStr = CommonFun.GetValue(content, "<div><li><span>", "\"><span>末页</span>"); pageStr = pageStr.Substring(pageStr.LastIndexOf("=") + 1); int totalPage = 0; if (!string.IsNullOrEmpty(pageStr)) { totalPage = Convert.ToInt32(pageStr); } for (int i = 2; i <= totalPage; i++) { content = http.HttpGet(url + "&p=" + i); itemStr = CommonFun.GetValue(content, "<form name=\"form\" method=\"post\">", "</form>"); ms = CommonFun.GetValues(itemStr, "<div class=\"white-box table-box\">", "<div class=\"span2 operationone\">"); foreach (Match m in ms) { CommonFun.WriteCSV("TKAdmin/down.csv", GetOneItem(m.Value)); } Console.WriteLine("{2}:totalPage:{0}, curPage:{1}", totalPage, i, DateTime.Now); } return(true); }
//<div class="span2" id="mall_price67369">20.99</div> //<div class="span2" id="market_price67369">21.00</div> //<div class="span1 money-box throughtmoney"> //<div class="money" id="stock67369">115</div> //<div><span>商品规格:</span>3g*15袋/盒</div> //<div><span>批准文号:</span>国药准字H19990307</div> //<div><span>生产厂家:</span>先声药业有限公司</div> public ItemInfo GetOneItem(string itemStr) { ItemInfo item = new ItemInfo(); item.Name = CommonFun.GetValue(itemStr, "; ", "</a>"); item.ID = CommonFun.GetValue(itemStr, "<span>批准文号:</span>", "</p>"); item.Format = CommonFun.GetValue(itemStr, "<span>商品规格:</span>", "</p>"); item.Created = CommonFun.GetValue(itemStr, "<span>生产企业:</span>", "</p>"); item.ViewCount = CommonFun.GetValue(itemStr, "value=\"", "\">"); item.Inventory = CommonFun.GetValue(itemStr, "stockEd=\"", "\""); item.Type = CommonFun.GetValue(itemStr, "promotionEd=\"", "\""); string priceStr = CommonFun.GetValue(itemStr, "priceEd=\"", "\""); item.PlatformPrice = Convert.ToDecimal(priceStr); return(item); }
/// <summary> /// 获取所有在售物品 /// </summary> /// <returns></returns> public bool ReadeAllSellingItme() { GetWebPageDate.Http.HttpRequest http = new GetWebPageDate.Http.HttpRequest(); http.CookieContainer = Login(); // http.Cookie = "acw_tc=AQAAAMj+8lkEeQUA3eT4OlKCFpqJmk95; Hm_lvt_3ad2c5e8712b25159b989a93a9927632=1510644101; Hm_lpvt_3ad2c5e8712b25159b989a93a9927632=1510645266; PHPSESSID=dem5mqnu6bfibviglvjh9d4ud1; Qs_lvt_150743=1509785002%2C1510643909%2C1510747212; nTalk_CACHE_DATA={uid:kf_9335_ISME9754_guestTEMP1758-0E75-6A,tid:1510643909116098}; NTKF_T2D_CLIENTID=guestTEMP1758-0E75-6A74-9EB9-8632DF7CEB19; Qs_pv_150743=2882295116553261000%2C1172614365052146400%2C979891720064693100%2C1505959923634373400%2C662315226244183900; Hm_lvt_ed70f863f631ecaac146592025767ed8=1509785002,1510643909; Hm_lpvt_ed70f863f631ecaac146592025767ed8=1510747235; sellerCooke=think%3A%7B%22sellerName%22%3A%22hankang%22%2C%22sellerStoreName%22%3A%22%25E9%2595%25BF%25E6%25B2%2599%25E5%258E%25BF001%25E5%25BA%2597%22%7D; Hm_lvt_7203bc79de07054ef3770e27e8ca9068=1509780503,1509934350,1510060776,1510543588; Hm_lpvt_7203bc79de07054ef3770e27e8ca9068=1510747284"; string content = http.HttpGet("https://admin.tkyfw.com/Goods/throughAudit?/Goods/throughAudit=&status=1&state=1"); string itemStr = CommonFun.GetValue(content, "<form name=\"form\" method=\"post\">", "</form>"); UpdateAllSellingItemPrice(itemStr, http); string pageStr = CommonFun.GetValue(content, "下一页", "><span>末页</span>"); pageStr = CommonFun.GetValue(pageStr, "&p=", "\""); pageStr = pageStr.Substring(pageStr.LastIndexOf("=") + 1); int totalPage = 0; if (!string.IsNullOrEmpty(pageStr)) { totalPage = Convert.ToInt32(pageStr); } for (int i = 2; i <= totalPage; i++) { if (i % 200 == 0) { http.CookieContainer = Login(); } content = http.HttpGet("https://admin.tkyfw.com/Goods/throughAudit?/Goods/throughAudit=&status=1&state=1&p=" + i); itemStr = CommonFun.GetValue(content, "<form name=\"form\" method=\"post\">", "</form>"); UpdateAllSellingItemPrice(itemStr, http); Console.WriteLine("{2}:totalPage:{0}, curPage:{1}", totalPage, i, DateTime.Now); } return(true); }
public override void ReadAllMenuURL() { string content = request.HttpGet(url); string mainMenuStr = CommonFun.GetValue(content, "nav bb1", "<div class=\"subcat-more\">"); MatchCollection ms = CommonFun.GetValues(mainMenuStr, "<div class=\"other\">", "</div>"); foreach (Match m in ms) { MatchCollection urlMs = CommonFun.GetValues(m.Value, "href=\"", "\""); foreach (Match urlM in urlMs) { if (!AllMenuUrl.Contains(urlM.Value)) { AllMenuUrl.Add(urlM.Value); } } } int startIndex = content.IndexOf("<div class=\"subcat-more\">"); int endIndex = content.LastIndexOf("<em>></em></a></div></div>"); string sumMenuStr = content.Substring(startIndex, endIndex - startIndex); MatchCollection ms1 = CommonFun.GetValues(sumMenuStr, "<a href=\"", "\""); foreach (Match m in ms1) { string tempUrl = m.Value; if (!AllItemUrl.Contains(tempUrl)) { if (!tempUrl.Contains("http")) { tempUrl = "http://www.yaofangwang.cn" + tempUrl; } AllMenuUrl.Add(tempUrl); } } }
private BaseItemInfo GetItem(string content) { try { BaseItemInfo item = new BaseItemInfo(); item.ID = CommonFun.GetValue(content, "\"approvalNum\":\"", "\""); item.Created = CommonFun.GetValue(content, "\"manufacturer\":\"", "\""); item.Format = CommonFun.GetValue(content, "\"packaging\":\"", "\""); item.Name = CommonFun.GetValue(content, "\"commonName\":\"", "\""); item.ItemName = CommonFun.GetValue(content, "\"name\":\"", "\""); item.ViewCount = CommonFun.GetValue(content, "\"skuId\":", ","); return(item); } catch (Exception ex) { Console.WriteLine(ex); } return(null); }
public override void ReadAllItemURL() { try { string muenUrl = "http://ad.dabai.7lk.com/medication/search"; foreach (string menuInfo in AllMenuUrl) { int page = 1; int totalPage = 0; do { string content = request.HttpPost(muenUrl, menuInfo + string.Format("&page={0}", page)); MatchCollection ms = CommonFun.GetValues(content, "\"id\":", ","); if (totalPage == 0) { string totalPageStr = CommonFun.GetValue(content, "\"totalPages\":", ","); totalPage = Convert.ToInt32(totalPageStr); } foreach (Match m in ms) { if (!AllItemUrl.Contains(m.Value)) { AllItemUrl.Add(m.Value); } } } while (++page <= totalPage); } } catch (Exception ex) { Console.WriteLine(ex); } }
/// <summary> /// 上架新品 /// </summary> public void UpNewItem() { Login(); BaseReadWebPage read = new BaseReadWebPage(); read.ReadBaseItemInfo("TYaoFang/20以上636493584245833259--------------.csv", true); int count = 0; foreach (BaseItemInfo item in read.ShopAllItems.Values) { try { if (count++ % 200 == 0) { Login(); } int startIndex = item.ID.IndexOf('字'); startIndex = (startIndex > 0 ? startIndex : item.ID.IndexOf('号')) + 1; string id = item.ID.Substring(startIndex, item.ID.Length - startIndex); // 查找商品模板 string seachUrl = "http://www.12yao.com/pharmacy/ajax_productinfo.php"; string postDataStr = "action=getProductSearch&keywords={0}&searchType=1"; string data = string.Format(postDataStr, id); string content = request.HttpPost(seachUrl, data, "http://www.12yao.com/pharmacy/productRelease.php?rootID=1", null, Encoding.GetEncoding("gb2312")); MatchCollection ms = CommonFun.GetValues(content, "<li>", "</li>"); foreach (Match m in ms) { //对比格式 string format = CommonFun.GetValue(m.Value, "<b>", "</b>"); if (format == item.Format) { string productID = CommonFun.GetValue(m.Value, "value='", "'"); string postDataStrInfo = "action=getProductInfo&ProductID={0}"; content = request.HttpPost(seachUrl, string.Format(postDataStrInfo, productID)); // 保存价格数据 string saveUrl = "http://www.12yao.com/pharmacy/SaveProduct.php"; string postDataSave = "PreferentialPrice={1}&RetailPrice={1}&ProductStock={2}&Weight=6&ProductCode={0}&standardCode=&REPID=&Base_ProductID={0}&action=addproductrelease&Submit=%CB%D1%CB%F7"; Random random = new Random((int)DateTime.Now.Ticks); content = request.HttpPost(saveUrl, string.Format(postDataSave, productID, item.PlatformPrice, random.Next(30, 40))); //获取待上架列表 string willUpUrl = string.Format("http://www.12yao.com/pharmacy/ProductUnderFrameList.php?ProductName=&ReasonShelves=0&ProductBatch={0}&CompanyTitle=&ProductCode=&ProductType=0&time1=&time2=", HttpUtility.UrlEncode(item.ID, Encoding.GetEncoding("gb2312")).ToUpper()); content = request.HttpGet(willUpUrl, null, Encoding.GetEncoding("gb2312")); bool isUp = false; if (!string.IsNullOrEmpty(content)) { MatchCollection upIdMs = CommonFun.GetValues(content, " <tr id=\"", " </tr>"); foreach (Match upIdM in upIdMs) { string willUpFormat = CommonFun.GetValue(upIdM.Value, "<td class=\"dgui\">", "</td>"); if (willUpFormat == item.Format) { string upId = CommonFun.GetValue(upIdM.Value, " value=\"", "\""); // 上架商品 string upUrl = "http://www.12yao.com/pharmacy/ProductsUnderFrame.php"; string postDataUp = "SelectPid={0}&action=setMultipleProductUpFrame"; string reuslt = request.HttpPost(upUrl, string.Format(postDataUp, upId)); isUp = true; } } } if (!isUp) { CommonFun.WriteCSV("TYaoFang/faild" + tick + ".csv", item); } } } } catch (Exception ex) { CommonFun.WriteCSV("TYaoFang/faild" + tick + ".csv", item); Console.WriteLine(ex); } } }
/// <summary> /// 获取平台最低价 /// </summary> /// <param name="id"></param> /// <param name="format"></param> /// <param name="http"></param> /// <returns></returns> public decimal GetPlatformPrice(string id, string format, Http.HttpRequest http, bool isSameOther = false) { try { decimal price = decimal.MaxValue; decimal otherPrice = decimal.MaxValue; int changeNum = 0; string url = string.Format("https://www.tkyfw.com/Ching_search.html?keyword={0}", id); string content = http.HttpGet(url); content = CommonFun.GetValue(content, "<ul class=\"seach_list\">", "</ul>"); MatchCollection ms = CommonFun.GetValues(content, "<li>", "</li>"); foreach (Match m in ms) { string item_format = CommonFun.GetValue(m.Value, "规格:", "</p>"); if (item_format == format) { MatchCollection urlMs = CommonFun.GetValues(m.Value, "<a href=\"", "\""); content = http.HttpGet("https://www.tkyfw.com" + urlMs[0].Value); MatchCollection itemMs = CommonFun.GetValues(content, "<div class=\"merinfo\">", "</label>"); foreach (Match itemM in itemMs) { string priceStr = CommonFun.GetValue(itemM.Value, "¥", "</p>"); string shopInfo = CommonFun.GetValue(itemM.Value, "市<span>-</span>", "</a>"); try { if (!string.IsNullOrEmpty(priceStr)) { decimal temp = Convert.ToDecimal(priceStr); if (temp != price) { changeNum++; } if (isSameOther && shopInfo == other_store_name) { otherPrice = temp; break; } else if (shopInfo != store_name) { if (temp < price) { price = temp; } } } } catch (Exception ex) { Console.WriteLine(ex); } } break; } } if (otherPrice != decimal.MaxValue) { return(otherPrice); } else { //if (changeNum == 1) //{ // return price; //} return(price); //if (price != decimal.MaxValue) //{ // return (price - (decimal)0.01); //} //else //{ // return price; //} } } catch (Exception ex) { Console.WriteLine(ex); } return(decimal.MaxValue); //return otherPrice != decimal.MaxValue ? otherPrice : (price - (decimal)0.01); }