コード例 #1
0
ファイル: ExcelReslove.cs プロジェクト: LacusCon/UrlResolve
        private void GetUrl(ExcelWorksheet ew, string inSheetName)
        {
            string _sheetName = inSheetName;
            url_struct _us;

            int rows = ew.Dimension.Rows;// ew.Cells.Rows;
            int start_row = 0;
            int start_col = 2;

            start_row = GetDataHead(ew, inSheetName);

            if (start_row == 0)
            {
                return;
            }

            //解析所有url
            for (int i = start_row; i < rows; i++)
            {
                int now_i = i + 1;
                for (int j = 0; j < 9; j++)
                {
                    string url_txt = ew.Cells[now_i, start_col + j + 1].Text;
                    if (String.IsNullOrEmpty(url_txt))
                    {
                        continue;
                    }

                    _us = new url_struct();
                    _us.sheet_name = _sheetName;
                    _us.game_name = ew.Cells[now_i, start_col].Text;
                    _us.platform = platform_list[j];
                    _us.url = ew.Cells[now_i, start_col + j + 1].Text;
                    _us.site = GetSiteName(_us.url);//TODO
                    url_list.Add(_us);
                }
            }

            //Console.WriteLine(ew.Name + "--GetUrl Completed--" + url_list.Count);
        }
コード例 #2
0
ファイル: ExcelReslove.cs プロジェクト: LacusCon/UrlResolve
        private void SetDownCount(ExcelWorksheets ews, url_struct result_st)
        {
            //get sheet
            for (int i = 0; i < ews.Count; i++)
            {
                int sheet_idx = i + 1;
                ExcelWorksheet ew = ews[sheet_idx];
                //Console.WriteLine(ews[sheet_idx].Name + "==SetDownCount==" + result_st.sheet_name + _after_name);
                if (ew.Name.Equals(result_st.sheet_name + _after_name))
                {
                    //Console.WriteLine("==SetDownCount Equal== " + ews[sheet_idx].Name);
                    int start_row = 0;

                    //得到起始行
                    start_row = GetDataHead(ew, ew.Name);

                    if (start_row == 0)
                    {
                        return;
                    }

                    //游戏名对照
                    for (int j = start_row; j < ew.Dimension.Rows; j++)
                    {
                        int now_j = j + 1;
                        if (ew.Cells[now_j, 2].Text.Equals(result_st.game_name))
                        {
                            int col_offset = 0;
                            for (int m = 0; m < platform_list.Count; m++)
                            {
                                if (result_st.platform.Equals(platform_list[m]))
                                {
                                    col_offset = m;
                                }
                            }

                            ew.Cells[now_j, col_offset + 5].Value = result_st.count;
                            //Console.WriteLine("==SetDownCount==" + result_st.game_name + "  Platform::" + result_st.platform + " Content::" + result_st.count);
                            return;
                        }
                    }

                }
            }
        }
コード例 #3
0
ファイル: ExcelReslove.cs プロジェクト: LacusCon/UrlResolve
        private void GetDownCount(url_struct us)
        {
            bool isExist = false;
            string node_func = "";
            if (web_key.ContainsKey(us.site))
            {
                isExist = true;
                node_func = web_key[us.site];
            }

            if (!isExist || String.IsNullOrEmpty(node_func))
            {
                StringBuilder sb = new StringBuilder("==Error== GetDownCount Sheet::").Append(us.sheet_name).Append("  Plateform::").Append(us.platform);
                errorList.Add(sb.ToString());
                Console.WriteLine(sb.ToString());
                return;
            }

            //Console.WriteLine("== GetDownCount ==" + ++test_count);

            HtmlWeb hw = new HtmlWeb();
            try
            {
                HtmlDocument htmlDoc = hw.Load(us.url);

                HtmlNodeCollection anchors = htmlDoc.DocumentNode.SelectNodes(node_func);//='download-num'
                int aCount = 0;
                string tmp_name = "";

                if (anchors == null || (anchors != null && anchors.Count == 0))
                {
                    StringBuilder sb = new StringBuilder("==Error== GetDownCount  aCount Sheet::").Append(us.sheet_name).Append("  Plateform::").Append(us.platform).Append(" Game::").Append(us.game_name).Append(" Result:0");
                    errorList.Add(sb.ToString());
                    Console.WriteLine(sb.ToString());
                    return;
                }

                foreach (var item in anchors)
                {
                    aCount++;

                    // 加入解析
                    tmp_name = GetResloveText(item.InnerText, GetSiteName(us.url));

                    //StringBuilder sb = new StringBuilder("==anchors ==  Sheet::").Append(us.sheet_name).Append(" Game::").Append(us.game_name).Append(" Platform::").Append(us.platform).Append(" URL::").Append(us.url).Append(" Content::").Append(tmp_name);
                    //Console.WriteLine(sb.ToString());
                    break;
                }

                if (aCount > 2)//TODO
                {
                    //StringBuilder sb = new StringBuilder("==Error== GetDownCount  aCount Sheet::").Append(us.sheet_name).Append("  Plateform::").Append(us.platform).Append(" ##").Append(aCount);
                    //errorList.Add(sb.ToString());
                    //Console.WriteLine(sb.ToString());
                    return;
                }

                url_struct res_st = new url_struct();
                res_st.sheet_name = us.sheet_name;
                res_st.game_name = us.game_name;
                res_st.platform = us.platform;
                res_st.site = us.site;
                res_st.count = tmp_name;
                result_list.Add(res_st);
            }
            catch (Exception ex)
            {
                StringBuilder sb = new StringBuilder(us.url).Append("== GetDownCount Exception==").Append(ex);
                errorList.Add(sb.ToString());
                Console.WriteLine(sb.ToString());
                throw;
            }
        }