public void GetMsnMoneyResponse() { var highPeRatio = 0.0; var lowPeRatio = 0.0; // how do i get around the number change? //https://www.msn.com/en-au/money/stockdetails/analysis/fi-146.1.ATV.NAS //https://www.msn.com/en-au/money/stockdetails/analysis/fi-126.1.ATV.NAS var url = GetMsnMoneyUrl(Code); using (var stream = Web.GetStream(url)) { HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument(); htmlDoc.Load(stream, Encoding.UTF8); if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0) { // Handle any parse errors as required } else { if (htmlDoc.DocumentNode != null) { HtmlAgilityPack.HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body"); if (bodyNode != null) { var pNodes = htmlDoc.DocumentNode.SelectNodes("//p"); if (pNodes != null) { var hasHighPeRatio = false; var hasLowPeRatio = false; foreach (var node in pNodes) { if (node.InnerText.Contains("P/E Ratio 5-Year High", StringComparison.OrdinalIgnoreCase)) { var parentNode = node.ParentNode.ParentNode.ParentNode; var childrenNodes = parentNode.SelectNodes("li"); foreach (var childNode in childrenNodes) { var childPNodes = childNode.SelectNodes("p"); foreach (var childTwoNode in childrenNodes) { var innerText = childTwoNode.InnerText; if (!string.IsNullOrEmpty(innerText) && !childTwoNode.InnerText.Contains("P/E Ratio 5-Year High", StringComparison.OrdinalIgnoreCase)) { double convertedInnerText; if (Double.TryParse(innerText, out convertedInnerText)) { highPeRatio = convertedInnerText; hasHighPeRatio = true; break; } } } if (hasHighPeRatio) { break; } } } else if (node.InnerText.Contains("P/E Ratio 5-Year Low", StringComparison.OrdinalIgnoreCase)) { var parentNode = node.ParentNode.ParentNode.ParentNode; var childrenNodes = parentNode.SelectNodes("li"); foreach (var childNode in childrenNodes) { var childPNodes = childNode.SelectNodes("p"); foreach (var childTwoNode in childrenNodes) { var innerText = childTwoNode.InnerText; if (!string.IsNullOrEmpty(innerText) && !childTwoNode.InnerText.Contains("P/E Ratio 5-Year Low", StringComparison.OrdinalIgnoreCase)) { double convertedInnerText; if (Double.TryParse(innerText, out convertedInnerText)) { lowPeRatio = convertedInnerText; hasLowPeRatio = true; break; } } } if (hasLowPeRatio) { break; } } } if (hasHighPeRatio && hasLowPeRatio) { // return average of high and low pe ratio SecondPeRatio.Value = (highPeRatio + lowPeRatio) / 2; SecondPeRatio.HasValue = true; break; } } } } } } } }
public void GetYahooFinanceResponse() { var url = GetYahooFinanceUrl(Code); using (var stream = Web.GetStream(url)) { HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument(); htmlDoc.Load(stream, Encoding.UTF8); if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0) { // Handle any parse errors as required } else { if (htmlDoc.DocumentNode != null) { HtmlAgilityPack.HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body"); if (bodyNode != null) { var spanNodes = htmlDoc.DocumentNode.SelectNodes("//span"); if (spanNodes != null) { var hasFoundSymbol = true; foreach (var node in spanNodes) { if (node.InnerText == string.Concat("Symbols similar to '")) { hasFoundSymbol = false; } } if (hasFoundSymbol) { foreach (var node in spanNodes) { if (!HasPrice) { GetPrice(node); } if (!HasTtmEps) { GetTtmEps(node); } if (HasPrice && HasTtmEps) { break; } } } } } } } } url = GetYahooFinanceUrl(Code, true); // get second eps using (var stream = Web.GetStream(url)) { HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument(); htmlDoc.Load(stream, Encoding.UTF8); if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0) { // Handle any parse errors as required } else { if (htmlDoc.DocumentNode != null) { HtmlAgilityPack.HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body"); if (bodyNode != null) { var spanNodes = htmlDoc.DocumentNode.SelectNodes("//span"); if (spanNodes != null) { var hasFoundSymbol = true; foreach (var node in spanNodes) { if (node.InnerText == string.Concat("Symbols similar to '") || node.InnerText == string.Concat("Analyst estimates are not available.")) { hasFoundSymbol = false; } } if (hasFoundSymbol) { foreach (var node in spanNodes) { if (!SecondEps.HasValue) { GetSecondEps(node); } if (SecondEps.HasValue) { break; } } } } } } } } }
public void GetWallStreetJournalResponse() { var url = GetWallStreetJournalUrl(Code); using (var stream = Web.GetStream(url)) { HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument(); htmlDoc.Load(stream, Encoding.UTF8); if (htmlDoc.ParseErrors != null && htmlDoc.ParseErrors.Count() > 0) { // Handle any parse errors as required } else { if (htmlDoc.DocumentNode != null) { HtmlAgilityPack.HtmlNode bodyNode = htmlDoc.DocumentNode.SelectSingleNode("//body"); if (bodyNode != null) { var tdNodes = htmlDoc.DocumentNode.SelectNodes("//td"); if (tdNodes != null) { foreach (var node in tdNodes) { if (node.InnerText.Contains("Total Equity", StringComparison.OrdinalIgnoreCase)) { var parentNode = node.ParentNode; if (parentNode.Name == "tr") { var equities = new List <double>(); var childrenNodes = parentNode.SelectNodes("td"); foreach (var childNode in childrenNodes) { var innerText = childNode.InnerText; if (!string.IsNullOrWhiteSpace(innerText) && !innerText.Contains("Total Equity", StringComparison.OrdinalIgnoreCase)) { innerText = innerText.Replace(",", ""); double convertedInnerText; if (Double.TryParse(innerText, out convertedInnerText)) { equities.Add(convertedInnerText); } } } if (equities.Count == 5) { double currentEquity = equities[0]; var ageEquity = equities.Count - 1; double initialEquity = equities[ageEquity]; // calculate equity growth percent https://www.wikihow.com/Calculate-Growth-Rate FirstEps.Value = Math.Pow((currentEquity / initialEquity), (1 / Convert.ToDouble(ageEquity))) - 1; FirstEps.HasValue = true; } } } if (FirstEps.HasValue) { break; } } } } } } } }