public void t2() { var s1 = File.ReadAllText("download2.txt"); s1 = Regex.Replace(s1, "itemDesc\":\"(.*?)\",\"itemName", "itemDesc\":\"nothing\",\"itemName"); s1 = s1.Remove(0, 1); s1 = s1.Remove(s1.Length - 1, 1); File.WriteAllText("temp_record.txt", s1); // JishiObject js1 = JsonConvert.DeserializeObject(s1, typeof(JishiObject)) as JishiObject; //1.抽数据 JiShi.BLL.js_item Bll = new JiShi.BLL.js_item(); foreach (var item in js1.pagedata) { JiShi.Model.js_item model = new JiShi.Model.js_item(); model.closed = item.closed.ToString(); model.createDate = item.createDate.ToString(); //if (!Bll.Exists(model.id)) { // LogManager.WriteLog("保存:" + Bll.Add(model)); //} } Console.WriteLine(js1.pageInfo.pageId + " " + js1.pageInfo.totalPages + " "); //Console.Write(js1); //Console.Write(JsonConvert.SerializeObject(js1)); //var s1="\"closed\":false,\"createDate\":\",\"curId\":18,"gameId":"","gameItemId":"","gender":"","grade":0,"gradeName":"","guild":"","iconPath":"http://180.153.139.98/res/money/yb.png","id":1518894,"itemAmount":1000000,"itemCode":"CapitalType2","itemDesc":"","itemName":"银子","itemType":"2199","power":"","price":88,"publicityEndDate":"2014-09-12 08:46:09","returnDate":"","saveTime":"2014-09-12 08:46:09","sellerCasId":"","sellerGameId":"B347C67E475948C582DFCE392B02AAA7","sellerRole":"郎纵横四海","serverId":"7100046","shelfDate":"2014-09-12 08:46:09","shelfDays":13,"status":"已上架","unitPrice":0}"; }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(JiShi.Model.js_item model) { return(dal.Update(model)); }
/// <summary> /// 每次都执行 /// </summary> private void OnPageLoaded_JiShi() { if (!jishi_start) { return; } var current_url = MainCefFrame.Url; if (!current_url.Contains("Goods") && !current_url.Contains("historicalJsonData") && !current_url.Contains("tradeItemDetail")) { return; } Domvisi2T dom1 = new Domvisi2T(); MainCefFrame.GetSource(dom1); var htm = GlobalVar.CurrentHtml; if (string.IsNullOrEmpty(htm)) { return; } ////角色分析模式 //if (analysisModel == "role") { // //数据导出 // LogManager.WriteLog("role-" + DateTime.Now.ToFileTime().ToString(), htm); // return; //} //物品分析模式 //0 数据过滤 htm = htm.Replace("<html><head></head><body>", ""); htm = htm.Replace("</body></html>", ""); htm = htm.Replace("</div>", ""); htm = htm.Replace("</font>", ""); // File.WriteAllText("tempload/temp_download-{0}.txt".With(DateTime.Now.ToFileTime()), htm); try { string s1 = ""; s1 = Regex.Replace(htm, "itemDesc\":\"(.*?)\",\"itemName", "itemDesc\":\"nothing\",\"itemName"); s1 = Regex.Replace(s1, "itemDesc\":\"(.*?)\",\"itemSellerRole", "itemDesc\":\"nothing\",\"itemSellerRole"); //itemSellerRole s1 = s1.Remove(0, 1); s1 = s1.Remove(s1.Length - 1, 1); //1.抽数据 JishiObject js1 = JsonConvert.DeserializeObject(s1, typeof(JishiObject)) as JishiObject; JiShi.BLL.js_item Bll = new JiShi.BLL.js_item(); foreach (var item in js1.pagedata) { #region MyRegion JiShi.Model.js_item model = new JiShi.Model.js_item(); model.closed = item.closed; model.createDate = item.createDate; model.gameId = item.gameId; model.gameItemId = item.gameItemId; model.gender = item.gender; model.gradeName = item.gradeName; model.guild = item.guild; model.iconPath = item.iconPath; model.itemCode = item.itemCode; model.itemDesc = item.itemDesc; model.itemName = item.itemName; model.itemType = item.itemType; model.power = item.power; model.publicityEndDate = item.publicityEndDate; model.sellerCasId = item.sellerCasId; model.sellerGameId = item.sellerGameId; model.sellerRole = item.sellerRole; model.serverId = item.serverId; //serverid部分数据会丢失 model.status = item.status; model.curId = item.curId; model.grade = item.grade; model.id = item.id; model.itemAmount = item.itemAmount.ToString(); model.price = item.price; model.returnDate = item.returnDate; model.saveTime = item.saveTime; model.shelfDate = item.shelfDate; model.shelfDays = item.shelfDays; model.closed = item.unitPrice; #endregion //为了对付 最近成交模式 if (model.id == null) { model.id = model.gameItemId; } // if (!Bll.Exists(model.id)) { model.status = modeList[modeListIndex]; LogManager.WriteLog("保存:" + model.gameId + " " + model.itemName + " " + Bll.Add(model)); } else { // LogManager.WriteLog("更新:" + model.gameId + " " + model.itemName + " " + Bll.Update(model)); } } //2.翻页 // Thread.Sleep(TimeSpan.FromSeconds(RandomManager.random.Next(2,4))); if (modeList[modeListIndex] == "historicalJsonData") { js1.pageInfo.totalPages = 6;//historicalJsonData模式下最多只能抓取6页 } Console.WriteLine("类型:" + modeList[modeListIndex] + " 页码:" + js1.pageInfo.pageId + " 总页数:" + js1.pageInfo.totalPages); if (js1.pageInfo.pageId < js1.pageInfo.totalPages) { jishi_next.PerformClick(); } else { if (modeListIndex + 1 < modeList.Count) { modeListIndex++; currentpage = -1; jishi_next.PerformClick(); } else { jishi_start = false; } } } catch (Exception e) { LogManager.WriteLog(e.ToString()); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(JiShi.Model.js_item model) { return(dal.Add(model)); }