Exemplo n.º 1
0
        //returns _regionsAndPercentages, also saves the same information to the file
        public override Dictionary <string, double> DoScrape()
        {
            //start an Action
            Task t = Task.Run(async() =>
            {
                try
                {
                    // asyncronous work which gets the raw html from url
                    string response = await _httpClient.GetStringAsync(_url);

                    // info for user
                    Console.WriteLine("\nInfo: Got a response from {0}", _url);

                    // parser result
                    _investmentPercentages = ParseResponse(response, Xpath); // Dictionary, scraper return result

                    // save to file
                    FileMethod filemethod = new FileMethod();
                    filemethod.DictionaryToTxtFile(_investmentPercentages, this._fundCode);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }).ContinueWith(t2 => Console.WriteLine("Info: Task for {0} is ready", this._fundCode));

            Console.WriteLine("\nInfo: Start downloading content from {0} to {1}, task id: {2} \n\nPlease wait...", _url, _fundCode, t.Id);

            t.Wait();

            return(_investmentPercentages);
        }