Esempio n. 1
0
        private async Task <ParserResult> RunAsync(ParserObject parserObject)
        {
            var result = new List <ParserResult>();

            var loader    = new HtmlLoader();
            var domParser = new HtmlParser();

            string dom = await loader.GetSourceByUri(parserObject.Uri);

            if (string.IsNullOrEmpty(dom))
            {
                throw new NullReferenceException($"Сould not get a response from {parserObject.Uri}");
            }

            IHtmlDocument document = await domParser.ParseDocumentAsync(dom);

            IElement domElement = document
                                  .QuerySelectorAll("td")
                                  .First(i => i.TextContent.Contains(parserObject.Pattern));

            string value = domElement
                           .SkipLine(document, parserObject.SkipAfterLines)
                           .QuerySelectorAll("span")
                           .Last(s => s.ClassName == parserObject.ClassName).TextContent;

            return(new ParserResult()
            {
                Hedar = parserObject.Pattern,
                Value = value
            });
        }
Esempio n. 2
0
 public ParserWorker(IParser <T> parser, IParserSettings parserSettings)
 {
     this.parser         = parser;
     this.parserSettings = parserSettings;
     loader = new HtmlLoader(parserSettings);
 }