private static List <Ability> GetAbilitiesList(AngleSharp.Dom.IElement mainDiv)
            {
                var abilitiesList = new List <Ability>();

                var abilitiesHeaders = mainDiv.QuerySelectorAll("h3");

                foreach (var header in abilitiesHeaders)
                {
                    string abilityName = header.TextContent.Trim();

                    var ability = new Ability {
                        name = abilityName
                    };

                    string description = "";
                    var    elem        = header.NextElementSibling;
                    while (elem != null && elem.NodeName != "H3")
                    {
                        description = description + HelperFunctions.ReadArbitraryElement(elem);

                        elem = elem.NextElementSibling;
                    }

                    ability.description = description;

                    ClassPageParser.FillOptions(ability, header);

                    abilitiesList.Add(ability);
                }


                return(abilitiesList);
            }
Пример #2
0
            private static dynamic HandleLink(string url, string fileName, Mode mode, Type type)
            {
                string subDirectory;

                switch (type)
                {
                case Type.Race:
                    subDirectory = "race_pages";
                    break;

                case Type.Background:
                    subDirectory = "background_pages";
                    break;

                case Type.Class:
                    subDirectory = "class_pages";
                    break;

                case Type.Subclass:
                    subDirectory = "subclass_pages";
                    break;

                case Type.Feat:
                    subDirectory = "feat_pages";
                    break;

                default:
                    throw new Exception("Invalid Type");
                }

                if (fileName.Contains('/'))
                {
                    fileName = fileName.Replace("/", "");
                }
                if (fileName.Contains(' '))
                {
                    fileName = fileName.Replace(" ", "_");
                }

                fileName = Config.DownloadedPagesDir + "/" + subDirectory + "/" + fileName + ".html.txt";


                string html;

                if (mode == Mode.ScrapeFiles)
                {
                    html = File.ReadAllText(fileName);
                }
                else
                {
                    html = HelperFunctions.GetHtmlFromUrl(url);
                }


                if (mode == Mode.ScrapeFiles)
                {
                    if (!Config.Silent)
                    {
                        Console.WriteLine("parsing: " + url);
                    }

                    switch (type)
                    {
                    case Type.Race:
                        return(RacePageParser.ParseRacePage(html));

                    case Type.Background:
                        return(null);

                    case Type.Class:
                        return(ClassPageParser.ParseClassPage(html));

                    case Type.Subclass:
                        return(SubclassPageParser.ParseSubclassPage(html));

                    case Type.Feat:
                        return(null);

                    default:
                        throw new Exception("Invalid Type");
                    }
                }
                else
                {
                    if (!Config.Silent)
                    {
                        Console.WriteLine("downloading: " + url);
                    }
                    File.WriteAllText(fileName, html);
                }


                return(null);
            }