Example #1
0
        /// <summary>
        /// 从HTML中找到当前页面所有值为innertext的链接
        /// </summary>
        /// <param name="cefFrame"></param>
        /// <param name="innerText"></param>
        public static List <string> GetUrlListByHapId(CefFrame cefFrame, string ElementId, string tagname, string attribute)
        {
            List <string> ls1 = new List <string>();

            try {
                var domvisit = new Domvisi2T();
                if (cefFrame == null)
                {
                    return(new List <string>());
                }
                new Thread(() => {
                    Thread.Sleep(1000);
                    cefFrame.GetSource(domvisit);
                }).Start();

                LogManager.WriteLog("阻塞");
                GlobalVar.IsloadOkAutoResetEvent.Reset();
                LogManager.WriteLog("默认阻塞,现在等待");
                GlobalVar.IsloadOkAutoResetEvent.WaitOne();


                ls1 = HtmlHelper.GetHrefs(domvisit.CurrentPageHtml, ElementId, tagname, attribute);
            } catch (Exception e1) {
                LogManager.WriteLog(e1.ToString());
            }
            return(ls1);
        }
Example #2
0
        /// <summary>
        /// 从HTML中找到当前页面所有值为innertext的链接
        /// </summary>
        /// <param name="cefFrame"></param>
        /// <param name="innerText"></param>
        public static List <string> GetUrlListByHap(CefFrame cefFrame, string innerText)
        {
            //LogManager.WriteLog("{0} 释放".With(innerText));
            //GlobalVar.IsloadOkAutoResetEvent.Set();

            var domvisit = new Domvisi2T();

            cefFrame.GetSource(domvisit);
            LogManager.WriteLog("{0} 默认阻塞,现在等待".With(innerText));
            GlobalVar.IsloadOkAutoResetEvent.WaitOne(TimeSpan.FromSeconds(10));
            LogManager.WriteLog("{0} 阻塞".With(innerText));
            GlobalVar.IsloadOkAutoResetEvent.Reset();
            var a1 = HtmlHelper.GetHrefs(domvisit.CurrentPageHtml, innerText);

            return(a1);
        }
Example #3
0
        public static List <string> GetInnerHtmlByHap(CefFrame cefFrame, string tagname, string attribute, string attributeValue)
        {
            var domvisit = new Domvisi2T();

            if (cefFrame == null)
            {
                return(new List <string>());
            }
            cefFrame.GetSource(domvisit);
            LogManager.WriteLog("默认阻塞,现在等待");
            GlobalVar.IsloadOkAutoResetEvent.WaitOne();
            LogManager.WriteLog("阻塞");
            GlobalVar.IsloadOkAutoResetEvent.Reset();
            var a1 = HtmlHelper.GetValue(domvisit.CurrentPageHtml, attributeValue, tagname, attribute);

            return(a1);
        }
Example #4
0
        /// <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());
            }
        }