private void ParseResult(string fileName) { try { HtmlDocument document = new HtmlDocument(); document.Load(fileName, System.Text.Encoding.UTF8); HtmlNode summaryNode = document.DocumentNode.SelectSingleNode("//div[@class='pass-summary']"); if (null == summaryNode) { return; } HtmlNodeCollection feeBeforeTaxNodes = summaryNode.SelectNodes(".//tr[@class='fares-người lớn']/td"); if (null == feeBeforeTaxNodes) { return; } int feeBeforeTaxNumber = 0; foreach (var feeBeforeTaxNode in feeBeforeTaxNodes) { string feeBeforeTax = Utilities.JestaExtractNumber(feeBeforeTaxNode.InnerText); try { feeBeforeTaxNumber += Convert.ToInt32(feeBeforeTax); } catch (Exception) { return; } } int taxNumber = 0; HtmlNodeCollection feeItemHeaderNodes = summaryNode.SelectNodes(".//th[@class='fee-item']"); foreach (var feeItemHeaderNode in feeItemHeaderNodes) { HtmlNode taxNode = feeItemHeaderNode.SelectSingleNode("..//span"); if (null != taxNode) { string tax = Utilities.ExtractNumber(taxNode.InnerText); try { taxNumber += Convert.ToInt32(tax); } catch (Exception) { return; } } } try { _result = new RegisterResult(); _result.FeeBeforeTax = feeBeforeTaxNumber.ToString(); _result.Tax = taxNumber.ToString(); string bookId = Path.GetRandomFileName(); bookId = bookId.Replace(".", ""); _result.BookId = bookId; _result.TotalFee = (feeBeforeTaxNumber + taxNumber).ToString(); } catch (Exception) { _result = null; } } catch (Exception) { } }
private void ParseResult(string fileName) { HtmlDocument document = new HtmlDocument(); document.Load(fileName); _result = null; HtmlNode root = document.DocumentNode; HtmlNode bookIdNode = root.SelectSingleNode("//span[@id='matdatcho']"); if (null == bookIdNode) { return; } string bookId = Utilities.ExtractNumberAndCharacter(bookIdNode.InnerText); HtmlNode priceDisplayTableNode = root.SelectSingleNode("//table[@id='priceDisplayTable']"); if (null == priceDisplayTableNode) { return; } HtmlNode feeBeforeTaxNode = priceDisplayTableNode.SelectSingleNode(".//tr[@class='farePriceFee']/td[@class='right']"); if (null == feeBeforeTaxNode) { return; } string feeBeforeTax = Utilities.ExtractNumber(feeBeforeTaxNode.InnerText); HtmlNode taxNode = priceDisplayTableNode.SelectSingleNode(".//tr[@class='feeTaxesFee']/td[@class='right']"); if (null == taxNode) { return; } string tax = Utilities.ExtractNumber(taxNode.InnerText); HtmlNode totalFeeNode = priceDisplayTableNode.SelectSingleNode(".//tr[@class='totalPrice']/td[@class='right']"); if (null == totalFeeNode) { return; } string totalFee = Utilities.ExtractNumber(totalFeeNode.InnerText); _result = new RegisterResult(); _result.BookId = bookId; _result.FeeBeforeTax = feeBeforeTax; _result.Tax = tax; _result.TotalFee = totalFee; }