Beispiel #1
0
        private void acquireInfoFromLocalPage()
        {
            if (!File.Exists(podPagePath))
            {
                return;
            }
            CurrentPicture = new Picture();
            HtmlDocument doc = new HtmlDocument();

            doc.Load(podPagePath);
            HtmlNode node = doc.DocumentNode.SelectSingleNode("descendant::div[attribute::id='caption']");

            if (node != null)
            {
                StringBuilder sb = new StringBuilder();
                foreach (HtmlNode n in node.ChildNodes)
                {
                    // Console.WriteLine(n.InnerText); // for debug only
                    if (PodUtil.IsAllWhiteSpace(n.InnerText))
                    {
                        continue;
                    }
                    if (n.OriginalName == "br") // n.OriginalName == "#text" ||
                    {
                        continue;
                    }
                    //if (n.InnerText.Contains("&")) // ???
                    //    continue;
                    if (n.OriginalName == "h2") // title
                    {
                        CurrentPicture.Title = n.InnerText;
                        continue;
                    }
                    bool hit = false;
                    foreach (HtmlAttribute a in n.Attributes)
                    {
                        if (a.Value == "publication_time")
                        {
                            CurrentPicture.Date = n.InnerText;
                            hit = true;
                            break;
                        }
                        if (a.Value == "credit")
                        {
                            CurrentPicture.Credit = PodUtil.ProcessGarbledChar(n.InnerText);
                            hit = true;
                            break;
                        }
                    }
                    if (hit)
                    {
                        continue;
                    }
                    sb.Append("\n" + n.InnerText + "\n");
                }
                CurrentPicture.Detail = PodUtil.RemoveConsecutiveWhiteSpaces(PodUtil.ProcessGarbledChar(sb.ToString()));

                //string captionString = node.InnerText;
                //string tempString = PodUtil.RemoveConsecutiveWhiteSpaces(captionString);

                //HtmlNode dateNode = node.SelectSingleNode("descendant::p[attribute::class='publication_time']");
                //if (dateNode != null)
                //{
                //    _date = dateNode.InnerText;
                //    tempString = PodUtil.RemoveSubstring(tempString, _date);
                //}
                //HtmlNode titleNode = node.SelectSingleNode("descendant::h2");
                //if(titleNode != null)
                //{
                //    _title = titleNode.InnerText;
                //    tempString = PodUtil.RemoveSubstring(tempString, _title);
                //}
                //tempString = PodUtil.RemoveConsecutiveWhiteSpaces(tempString);
                //_detail = PodUtil.ProcessGarbledChar(tempString);

                // the following is not working because the <p> not being properly closed
                //HtmlNode detailNode = node.SelectSingleNode("descendant::p[3]");
                //if(detailNode != null)
                //{
                //    _detail = detailNode.InnerText;
                //}
            }
            GetPicUrl(false);
        }