コード例 #1
0
        public HtmlTableExtract GetTable(string file, string section)
        {
            HtmlTableExtract hte = new HtmlTableExtract();

            int index = file.IndexOf(section);

            string header    = file.Substring(0, index);
            int    lastIndex = header.LastIndexOf("<table");

            int headerindex = file.IndexOf("/table");

            string sectionText = file.Substring(lastIndex, (index + headerindex) - lastIndex);

            string[] lines = sectionText.Split("<tr>");

            foreach (string line in lines)
            {
                string[] parts = line.Split("<td>");
                if (parts.Length == 2)
                {
                    hte.AddTableLine(parts);
                }
                else
                {
                    hte.SetHeader(line);
                }
            }

            return(hte);
        }
コード例 #2
0
        public LocomotiveDetails CreateDB(string url)
        {
            HtmlTableExtract     table     = GetTable(url, string.Empty);
            HtmlTableExtractLoco tableLoco = new HtmlTableExtractLoco(table);
            var loco = BuildDB(tableLoco, url);

            var ldb = LocomotiveDBServices.GetDBServices();

            ldb.Add(loco);

            return(loco);
        }
コード例 #3
0
        public void UpdateFromSite()
        {
            LocomotivesServices  ls            = ServiceLocator.Instance.GetService <LocomotivesServices>();
            HtmlTableExtract     table         = ls.GetTable(WebSite, string.Empty);
            HtmlTableExtractLoco latestVersion = new HtmlTableExtractLoco(table);

            if (Operators == MISSING)
            {
                Operators = latestVersion.Operators;
                SetDirty();
            }

            if (Class == MISSING)
            {
                Class = latestVersion.Class;
                SetDirty();
            }
        }
コード例 #4
0
        public static HtmlTableExtract GetTable(string file, string section)
        {
            HtmlTableExtract hte = new HtmlTableExtract();

            if (string.IsNullOrWhiteSpace(file))
            {
                return(hte);
            }

            int index = file.IndexOf(section);

            string header    = file.Substring(0, index);
            int    lastIndex = header.LastIndexOf("<table");

            int headerindex = file.IndexOf("/table");

            string sectionText = file.Substring(lastIndex, (index + headerindex) - lastIndex);

            string[] lines = sectionText.Split("<tr>");

            foreach (string line in lines)
            {
                string[] parts = line.Split("<td>");
                if (parts.Length == 2)
                {
                    hte.AddTableLine(parts);
                }
                else
                {
                    hte.SetHeader(line);
                }
            }

            index = file.IndexOf("<table class=\"infobox\"");

            string results = HTMLExtraction.GetTagLine(file, "th", index);

            results = HTMLRemover.RemoveAnyTags(results, "br");
            results = HTMLRemover.GetTextBetweenTags(results);

            hte.DisplayName = results;

            return(hte);
        }
コード例 #5
0
 public HtmlTableExtractLoco(HtmlTableExtract htmlTableExtract)
 {
     _htmlTableExtract = htmlTableExtract;
 }