Пример #1
0
        public MiMFa_Table GetTable(MiMFa_Table dt, HTMLElementPatern elementPatern, List <MiMFa_XMLElement> xmls, out MiMFa_XMLElement elem)
        {
            elem = null;
            switch (elementPatern.ElementSimilarity)
            {
            case MiMFa_Similarity.Congruent:
                elem = MiMFa_XMLElement.FindCongruent(xmls, elementPatern.SampleHTMLElement);
                break;

            case MiMFa_Similarity.Like:
                elem = MiMFa_XMLElement.FindLike(xmls, elementPatern.SampleHTMLElement);
                break;

            case MiMFa_Similarity.Same:
                elem = MiMFa_XMLElement.FindSame(xmls, elementPatern.SampleHTMLElement);
                break;

            case MiMFa_Similarity.Duplicate:
                elem = MiMFa_XMLElement.FindDuplicate(xmls, elementPatern.SampleHTMLElement);
                break;

            case MiMFa_Similarity.This:
                elem = MiMFa_XMLElement.Find(xmls, elementPatern.SampleHTMLElement);
                break;
            }
            return(AddInTable(dt, elementPatern, elem, xmls));
        }
Пример #2
0
        public MiMFa_Table GetTable(FetchPatern patern, List <MiMFa_XMLElement> xmls)
        {
            MiMFa_Table mdt = new MiMFa_Table();

            if (patern.HTMLElementsPatern == null)
            {
                return(mdt);
            }
            List <HTMLElementPatern> continuehep = new List <HTMLElementPatern>();

            MiMFa_CollectionService.CopyTo(ref continuehep, patern.HTMLElementsPatern);
            List <MiMFa_XMLElement> me = new List <MiMFa_XMLElement>();

            foreach (var item in patern.HTMLElementsPatern)
            {
                me.Add(item.SampleHTMLElement);
            }
            MiMFa_XMLElement e = MiMFa_XMLElement.GetElementsCommonParent(me);

            while (continuehep.Count > 0)
            {
                if (e != null)
                {
                    e = MiMFa_XMLElement.Find(xmls, e);
                }
                List <MiMFa_XMLElement> scope = e == null ? xmls : new List <MiMFa_XMLElement>()
                {
                    e
                };
                bool             all  = false;
                MiMFa_XMLElement elem = null;
                int len = continuehep.Count;
                for (int i = 0; i < len; i++)
                {
                    MiMFa_XMLElement ele = null;
                    mdt = GetTable(mdt, continuehep[i], scope, out ele);
                    if (continuehep[i].All != MiMFa_Boolean.True)
                    {
                        continuehep.RemoveAt(i);
                        i--;
                        len--;
                    }
                    else if (ele != null)
                    {
                        elem = ele;
                        all  = true;
                    }
                    if (ele != null)
                    {
                        if (continuehep.Count - 1 > i + 1 && continuehep[i].SampleHTMLElement == continuehep[i + 1].SampleHTMLElement.Parent)
                        {
                            ele.StartTag = "";
                        }
                        else
                        {
                            xmls = MiMFa_XMLElement.GetLastSplitIn(xmls, ele);
                        }
                    }
                }
                if (e == null)
                {
                    break;
                }
                if (elem == null)
                {
                    xmls = MiMFa_XMLElement.GetLastSplitIn(xmls, e);
                }
                else if (all)
                {
                    xmls = MiMFa_XMLElement.GetLastSplitIn(xmls, elem);
                }
                else
                {
                    break;
                }
            }
            //
            if (fetch_url.TransposeResult)
            {
                mdt = mdt.Transpose(true);
            }
            NumberOfLastTableRows = mdt.MainTable.Rows.Count - 1;
            NumberOfAllTableRows += NumberOfLastTableRows;
            if (string.IsNullOrWhiteSpace(fetch_url.TableAddress))
            {
                fetch_url.TableAddress = TempDirectory + DateTime.Now.Ticks + MiMFa_Table.Extention;
            }
            if (NumberOfLastTableRows > 0)
            {
                try
                {
                    if (!string.IsNullOrWhiteSpace(fetch_url.Source))
                    {
                        DataColumn dcs = mdt.AddColumnSafe("auto_Source");
                        for (int i = 1; i < mdt.Rows.Count; i++)
                        {
                            mdt.Rows[i][dcs] = fetch_url.Source;
                        }
                    }
                }
                catch { }
            }
            try
            {
                MiMFa_Table nmt = null;
                MiMFa_IOService.OpenDeserializeFile(fetch_url.TableAddress, ref nmt);
                if (nmt != null)
                {
                    nmt = MiMFa_Table.ConcatTable(nmt, mdt);
                }
            }
            catch { }
            MiMFa_IOService.SaveSerializeFile(fetch_url.TableAddress, mdt);
            return(mdt);
        }