Exemplo n.º 1
0
        public LaoHLDayEx(ZHtmlParser pr)
        {
            // EXAMPlE: m_yearOrder = new LaoHLEntryEx("岁次", "//*[@id=\"con01-0\"]/div[2]/div[2]/table/tr[1]/td[2]/text()", 0); // 注意:xpath 里的 tbody 须忽略!!!

            for (int i = 0; i < m_length; i++)
            {
                m_ancient_hour[i] = new LaoHLEntryEx("时辰简称", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[1]/td[{0}]/text()", i + 2));
                m_solar_time_start[i] = new LaoHLEntryEx("时刻开始", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[2]/td[{0}]/text()", i + 2), 0);
                m_solar_time_end[i] = new LaoHLEntryEx("时刻结束", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[2]/td[{0}]/text()", i + 2), 1);
                m_ancient_hour_fullname[i] = new LaoHLEntryEx("时辰全称", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[3]/td[{0}]/text()", i + 2));
                m_star_god[i] = new LaoHLEntryEx("星神", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[4]/td[{0}]/text()", i + 2));
                m_straight_confict[i] = new LaoHLEntryEx("正冲", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[5]/td[{0}]/text()", i + 2));
                m_good_ill_luck[i] = new LaoHLEntryEx("吉凶", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[6]/td[{0}]", i + 2));
                m_zodiac_timed[i] = new LaoHLEntryEx("生肖", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[7]/td[{0}]/text()", i + 2));
                m_good_god[i] = new LaoHLEntryEx("吉神", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[8]/td[{0}]/div", i + 2));
                m_ill_god[i] = new LaoHLEntryEx("凶煞", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[9]/td[{0}]/div", i + 2));
                m_well_timed[i] = new LaoHLEntryEx("时宜", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[10]/td[{0}]/div", i + 2));
                m_bad_timed[i] = new LaoHLEntryEx("时忌", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[11]/td[{0}]/div", i + 2));
                m_fiveElem_timed[i] = new LaoHLEntryEx("五行", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[12]/td[{0}]/text()", i + 2));
                m_conflict_orientation[i] = new LaoHLEntryEx("煞方", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[13]/td[{0}]/text()", i + 2));
                m_happy_god[i] = new LaoHLEntryEx("喜神", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[14]/td[{0}]/text()[1]", i + 2), 0);
                m_fortune_god[i] = new LaoHLEntryEx("财神", string.Format("//*[@id=\"USkin_bk\"]/table[14]/tr/td/div/table[1]/tr[14]/td[{0}]/text()[2]", i + 2), 0);

                // 额外处理
                m_good_ill_luck[i].m_customParser = getGoodIllLuckValue;

                // 为Entry 实例的 Parser 对象赋值,将会同时完成相应数值的解析
                m_ancient_hour[i].Parser = pr;
                m_ancient_hour_fullname[i].Parser = pr;
                m_solar_time_start[i].Parser = pr;
                m_solar_time_end[i].Parser = pr;
                m_star_god[i].Parser = pr;
                m_straight_confict[i].Parser = pr;
                m_good_ill_luck[i].Parser = pr;
                m_zodiac_timed[i].Parser = pr;
                m_good_god[i].Parser = pr;
                m_ill_god[i].Parser = pr;
                m_well_timed[i].Parser = pr;
                m_bad_timed[i].Parser = pr;
                m_fiveElem_timed[i].Parser = pr;
                m_conflict_orientation[i].Parser = pr;
                m_happy_god[i].Parser = pr;
                m_fortune_god[i].Parser = pr;
            }
        }
Exemplo n.º 2
0
            public SinaHLEntryEx m_zodiac; // 生肖

            #endregion Fields

            #region Constructors

            public SinaHLDayEx(ZHtmlParser pr)
            {
                m_date        = new SinaHLEntryEx("公历","//*[@id=\"con01-0\"]/div[2]/div[2]/p/text()",0);
                m_solarDate   = new SinaHLEntryEx("公历", "//*[@id=\"con01-0\"]/div[2]/div[2]/p/text()", 0);
                m_lunarDate   = new SinaHLEntryEx("农历","//*[@id=\"con01-0\"]/div[2]/div[2]/p/text()", 1);
                m_yearOrder   = new SinaHLEntryEx("岁次","//*[@id=\"con01-0\"]/div[2]/div[2]/table/tr[1]/td[2]/text()",0); // 注意:xpath 里的 tbody 须忽略!!!
                m_zodiac      = new SinaHLEntryEx("岁次","//*[@id=\"con01-0\"]/div[2]/div[2]/table/tr[1]/td[2]/text()",1);
                m_monthOrder  = new SinaHLEntryEx("岁次","//*[@id=\"con01-0\"]/div[2]/div[2]/table/tr[1]/td[2]/text()",2);
                m_dayOrder    = new SinaHLEntryEx("岁次","//*[@id=\"con01-0\"]/div[2]/div[2]/table/tr[1]/td[2]/text()",3);
                m_birthGod    = new SinaHLEntryEx("日胎神占方","//*[@id=\"con01-0\"]/div[2]/div[2]/table/tr[2]/td[2]/text()");
                m_fiveElem    = new SinaHLEntryEx("五行","//*[@id=\"con01-0\"]/div[2]/div[2]/table/tr[3]/td[2]/text()");
                m_collide     = new SinaHLEntryEx("冲", "//*[@id=\"con01-0\"]/div[2]/div[2]/table/tr[4]/td[2]/text()");
                m_pengAvoid   = new SinaHLEntryEx("彭祖百忌","//*[@id=\"con01-0\"]/div[2]/div[2]/table/tr[5]/td[2]/text()");
                m_goodAngelYi = new SinaHLEntryEx("吉神宜趋","//*[@id=\"con01-0\"]/div[2]/div[2]/table/tr[6]/td[2]/text()");
                m_evilAngelJi = new SinaHLEntryEx("凶神宜忌", "//*[@id=\"con01-0\"]/div[2]/div[2]/table/tr[8]/td[2]/text()");
                m_Yi = new SinaHLEntryEx("宜","//*[@id=\"con01-0\"]/div[2]/div[2]/table/tr[7]/td[2]/text()");
                m_Ji = new SinaHLEntryEx("忌", "//*[@id=\"con01-0\"]/div[2]/div[2]/table/tr[9]/td[2]/text()");

                // 为Entry 实例的 Parser 对象赋值,将会同时完成相应数值的解析
                m_date.Parser = pr;
                m_solarDate.Parser = pr;
                m_lunarDate.Parser = pr;
                m_yearOrder.Parser = pr;
                m_zodiac.Parser = pr;
                m_monthOrder.Parser = pr;
                m_dayOrder.Parser = pr;
                m_birthGod.Parser = pr;
                m_fiveElem.Parser = pr;
                m_collide.Parser = pr;
                m_pengAvoid.Parser = pr;
                m_goodAngelYi.Parser = pr;
                m_evilAngelJi.Parser = pr;
                m_Yi.Parser = pr;
                m_Ji.Parser = pr;
            }
Exemplo n.º 3
0
        private string getOutputFileName(int pageIdx)
        {
            string filename = null;

            if (m_strHtml != null && m_strHtml != "")
            {
                ZHtmlParser pr = new ZHtmlParser(m_strHtml);
                Entry entry = new Entry(pr);
                entry.xpath = "//*[@id=\"con01-0\"]/div[2]/div[2]/p/text()";

                string[] values = entry.val.Split(' ');
                string fex = values[0];

                filename = string.Format("{0}\\{1}.{2}.{3}", _SINAHUANGDAOBOOK_DIR_, _OUTFILE_PREFIX_, fex, "html");
            }
            else
            {
                filename = string.Format("{0}\\{1}.{2}.{3}", _SINAHUANGDAOBOOK_DIR_, _OUTFILE_PREFIX_, pageIdx, "html");
            }

            return filename;
        }
Exemplo n.º 4
0
        public int parseHLDayFiles(string dirpath)
        {
            int nResult = 0;

            SinaHDDB db = new SinaHDDB();
            db.initDb();

            string[] filenames = Directory.GetFiles(dirpath);
            foreach (string fn in filenames)
            {
                FileStream fs = new FileStream(fn, FileMode.Open);
                if (fs != null)
                {
                    TextReader tr = new StreamReader(fs);
                    string strHtml = tr.ReadToEnd();
                    ZHtmlParser htmlParser = new ZHtmlParser(strHtml);
                    SinaHLDayEx hlday = new SinaHLDayEx(htmlParser);

                    db.saveToDb(hlday);

                    tr.Close();
                }
                fs.Close();
            }
            db.closeDb();
            return nResult;
        }
Exemplo n.º 5
0
        private string getOutputFileName(int pageIdx)
        {
            // return string.Format("{0}\\{1}.{2}", _BIRTHDAYBOOK_DIR_, i, Path.GetFileName(Path.GetTempFileName()));

            string filename = null;

            if (m_strHtml != null && m_strHtml != "")
            {
                ZHtmlParser pr = new ZHtmlParser(m_strHtml);
                Entry entry = new Entry(pr);
                entry.xpath = "//*[@id=\"wrap\"]/h3/text()";

                filename = string.Format("{0}\\{1}.{2}.{3}", _MONTHDAYBOOK_DIR_, _OUTFILE_PREFIX_, entry.val, "html");
            }
            else
            {
                filename = string.Format("{0}\\{1}.{2}.{3}", _MONTHDAYBOOK_DIR_, _OUTFILE_PREFIX_, pageIdx, "html");
            }

            return filename;
        }
Exemplo n.º 6
0
 public BookEntry(ZHtmlParser pr)
 {
     _parser = pr;
 }
Exemplo n.º 7
0
        private void parseWebData()
        {
            string strHtml = readTmpData(m_tmp_filename);

            if (strHtml != null && strHtml != "")
            {
                ZHtmlParser htmlParser = new ZHtmlParser(strHtml);

                BookEntry Characters = new BookEntry();
                Characters.Parser = htmlParser;
                Characters.name.xpath = "//*[@id=\"wrap\"]/p[1]/text()";
                Characters.summary.xpath = "//*[@id=\"wrap\"]/p[2]/text()";
                Characters.description.xpath = "//*[@id=\"wrap\"]/p[3]/text()";

                BookEntry Affection = new BookEntry();
                Affection.Parser = htmlParser;
                Affection.name.xpath = "//*[@id=\"wrap\"]/p[5]/text()";
                Affection.summary.xpath = "//*[@id=\"wrap\"]/p[6]/text()";
                Affection.description.xpath = "//*[@id=\"wrap\"]/p[7]/text()";

                BookEntry MoneyLuck = new BookEntry();
                MoneyLuck.Parser = htmlParser;
                MoneyLuck.name.xpath = "//*[@id=\"wrap\"]/p[8]/text()";
                MoneyLuck.summary.xpath = "//*[@id=\"wrap\"]/p[9]/text()";
                MoneyLuck.description.xpath = "//*[@id=\"wrap\"]/p[10]/text()";

                BookEntry CareerLuck = new BookEntry();
                CareerLuck.Parser = htmlParser;
                CareerLuck.name.xpath = "//*[@id=\"wrap\"]/p[11]/text()";
                CareerLuck.summary.xpath = "//*[@id=\"wrap\"]/p[12]/text()";
                CareerLuck.description.xpath = "//*[@id=\"wrap\"]/p[13]/text()";

                BookEntry HealthLuck = new BookEntry();
                HealthLuck.Parser = htmlParser;
                HealthLuck.name.xpath = "//*[@id=\"wrap\"]/p[14]/text()";
                HealthLuck.summary.xpath = "//*[@id=\"wrap\"]/p[15]/text()";
                HealthLuck.description.xpath = "//*[@id=\"wrap\"]/p[16]/text()";

                BookEntry LuckyNumber = new BookEntry();
                LuckyNumber.Parser = htmlParser;
                LuckyNumber.name.xpath = "//*[@id=\"wrap\"]/p[17]/text()";
                LuckyNumber.summary.xpath = "//*[@id=\"wrap\"]/p[18]/text()";
                LuckyNumber.description.xpath = "//*[@id=\"wrap\"]/p[19]/text()";

                BookEntry MatchLover = new BookEntry();
                MatchLover.Parser = htmlParser;
                MatchLover.name.xpath = "//*[@id=\"wrap\"]/p[20]/text()";
                MatchLover.summary.xpath = "";
                MatchLover.description.xpath = "//*[@id=\"wrap\"]/p[22]/text()";

                BookEntry MatchFriend = new BookEntry();
                MatchFriend.Parser = htmlParser;
                MatchFriend.name.xpath = "//*[@id=\"wrap\"]/p[22]/text()";
                MatchFriend.summary.xpath = "";
                MatchFriend.description.xpath = "//*[@id=\"wrap\"]/p[23]/text()";
            }
        }
Exemplo n.º 8
0
        public int parseHLDayFiles(string dirpath)
        {
            int nResult = 0;

            HdDBHelper db = new HdDBHelper();

            string[] filenames = Directory.GetFiles(dirpath);
            foreach (string fn in filenames)
            {
                FileStream fs = new FileStream(fn, FileMode.Open);
                if (fs != null)
                {
                    TextReader tr = new StreamReader(fs);
                    string strHtml = tr.ReadToEnd();
                    ZHtmlParser htmlParser = new ZHtmlParser(strHtml);
                    LaoHLDayEx lhlday = new LaoHLDayEx(htmlParser);

                    db.saveToDb(lhlday);

                    tr.Close();
                }
                fs.Close();
            }

            return nResult;
        }