Esempio n. 1
0
        private void ExtractFieldResult(Content content)
        {
            var fieldResultList = new List <FieldResult>();

            foreach (var m in FieldList)
            {
                var objContent = content.Clone();

                //主要规则
                var item = new FieldResult
                {
                    Title     = m.Title,
                    DataName  = m.DataName,
                    DataValue = m.Exec(objContent as Content).ContentText,
                    Require   = m.Require,
                    Sort      = m.Sort
                };

                //备用规则
                if (m.Require && string.IsNullOrEmpty(item.DataValue))
                {
                    item.DataValue = m.Exec2(objContent as Content).ContentText;
                }

                fieldResultList.Add(item);
            }

            PublishResult(fieldResultList);
        }
Esempio n. 2
0
        /// <summary>
        /// Install-Package Jumony.Core
        /// //*[@id="jingzhun"]
        /// //*[@id="infolist"]/table
        /// </summary>
        /// <param name="content"></param>
        private void ExtractTableFieldResult(Content content)
        {
            var doc = new HtmlDocument();

            doc.LoadHtml(content.ContentText);

            var tableNode = doc.DocumentNode.SelectSingleNode(TableXPath);

            if (tableNode == null)
            {
                return;
            }

            var trNodes = tableNode.Elements("tr");

            foreach (var tr in trNodes)
            {
                var fieldResultList = new List <FieldResult>();
                var tdNodes         = tr.Elements("td").ToList();

                for (var i = 0; i < tdNodes.Count; i++)
                {
                    var fields = FieldList.Where(p => p.Index == i).ToList();
                    foreach (var m in fields)
                    {
                        var con = new Content
                        {
                            ContentText = tdNodes[i].InnerHtml,
                            Session     = content.Session
                        };
                        var item = new FieldResult
                        {
                            Title     = m.Title,
                            DataName  = m.DataName,
                            DataValue = m.Exec(con).ContentText,
                            Require   = m.Require,
                            Sort      = m.Sort
                        };
                        fieldResultList.Add(item);
                    }
                }

                PublishResult(fieldResultList);
            }
        }