Beispiel #1
0
        private IEnumerable <string> SplitBy(string s, Predicate <char> isSplitter)
        {
            var inQuote = false;
            var last    = 0;

            foreach (var(c, i, b) in JsonValueHelper.DeEscape(s, () => inQuote))
            {
                if ((c == '"' || c == '\'') && !b) // doesn't pair, assuming user takes care
                {
                    inQuote = !inQuote;
                    continue;
                }

                if (!inQuote && isSplitter(c))
                {
                    if (i > last)
                    {
                        yield return(s.Substring(last, i - last));
                    }
                    last = i + 1;
                }
            }

            var t = s.Substring(last, s.Length - last);

            if (!string.IsNullOrWhiteSpace(t))
            {
                yield return(t);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets the scraping helper.
        /// </summary>
        /// <param name="scrapType">Type of the scrap.</param>
        /// <param name="document">The document.</param>
        /// <returns>IScrapingHelper</returns>
        public static IScrapingHelper GetScrapingHelper(ScrapingType scrapType, string document)
        {
            IScrapingHelper result;

            switch (scrapType)
            {
            case ScrapingType.HTMLValue:
                result = new HTMLValueHelper(document);
                break;

            case ScrapingType.HTMLDoc:
                result = new HTMLDocHelper(document);
                break;

            case ScrapingType.JsonDoc:
                result = new JsonDocHelper(document);
                break;

            case ScrapingType.ApiUrl:
                result = new ApiUrlHelper(document);
                break;

            case ScrapingType.WebUrl:
                result = new WebUrlHelper(document);
                break;

            case ScrapingType.Text:
                result = new TextHelper(document);
                break;

            case ScrapingType.HTMLAttribute:
                result = new HTMLAttributeHelper(document);
                break;

            case ScrapingType.JsonVlue:
                result = new JsonValueHelper(document);
                break;

            //case ScrapingType.WebDriver:
            // //   result = new WebDriverHelper(document);
            //    break;
            //case ScrapingType.Header:
            //   // result = new HeaderHelper(document);
            //    break;
            default:
                result = new ApiUrlHelper(document);
                break;
            }
            return(result);
        }