Ejemplo n.º 1
0
 public EmailSetting(HtmlAgilityPack.HtmlNode emailData)
 {
     // process the data to get the email settings
     
     EmailAddress = emailData.SelectSingleNode(String.Format(".//input[@name='{0}']", FormInputNames.EmailSettings.EmailAddress))?.GetAttributeValue("value", "");
     EmailReceipts = emailData.SelectSingleNode(String.Format(".//input[@name='{0}']", FormInputNames.EmailSettings.EmailRecipientsCheckBox))?.GetAttributeValue("checked", "off") == "checked" ? true : false;
     TextReminders = emailData.SelectSingleNode(String.Format(".//input[@name='{0}']", FormInputNames.EmailSettings.TextRemindersCheckBox))?.GetAttributeValue("checked", "off") == "checked" ? true : false;
     var select = emailData.SelectSingleNode(String.Format(".//select[@name='{0}']", FormInputNames.EmailSettings.DropDownPreferredLanguage));
     Language = select.SelectSingleNode(".//option[@selected='selected']")?.GetAttributeValue("value", "");
 }
Ejemplo n.º 2
0
            public TermsConditions(HtmlAgilityPack.HtmlNode tc)
            {
                // process the data to get the security settings                                
                var node = tc.SelectSingleNode("//userlog");
                InfoHtml = node.OuterHtml;
                InfoText = node.InnerText;

            }
 public decimal GetDishPrice(HtmlAgilityPack.HtmlNode dishNode)
 {
     var dishPriceNode = dishNode.SelectSingleNode(".//span[@class='price']");
     var dishPrice = dishPriceNode == null ? "0" : dishPriceNode.InnerText.Replace("¥", string.Empty).ClearSiteCode();
     decimal priceDecimal = 0;
     decimal.TryParse(dishPrice, out priceDecimal);
     return priceDecimal;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// parset planetinformationen
        /// </summary>
        /// <param name="planetNode">Html Knoten, der die Planetinformationen enthält</param>
        public Planet(HtmlAgilityPack.HtmlNode planetNode, StringManager strings, Logger logger)
        {
            logger.Log (LoggingCategories.Parse, "Planet Constructor");
            this._name = planetNode.SelectSingleNode (strings.PlanetNameXPath).InnerText;

            //Koordinaten auslesen:
            string coordsString = planetNode.SelectSingleNode (strings.PlanetCoordsXPath).InnerText;
            System.Text.RegularExpressions.Match match = System.Text.RegularExpressions.Regex.Match (coordsString, strings.PlanetCoordsRegex);

            //Koordinaten Parsen
            this._coords.Galaxy = Convert.ToInt32 (match.Groups [1].Value);
            this._coords.SunSystem = Convert.ToInt32 (match.Groups [2].Value);
            this._coords.Place = Convert.ToInt32 (match.Groups [3].Value);

            //Link auslesen:
            string linktToPlanet = planetNode.SelectSingleNode (strings.PlanetLinkXPath).Attributes ["href"].Value;
            this._id = Utils.StringReplaceToInt32 (Utils.SimpleRegex (linktToPlanet, strings.PlanetIDRegex));
        }
Ejemplo n.º 5
0
 public static Vehicle Parse(HtmlAgilityPack.HtmlNode htmlData)
 {
     var vehicleInput = htmlData.SelectSingleNode(".//input[@type='text']/@value");
     if (vehicleInput == null)
     {
         // not a vehicle row
         return null;
     }
     return new Vehicle(htmlData);
 }
Ejemplo n.º 6
0
		public static string GetAttribute(HtmlAgilityPack.HtmlNode doc, string xpath, string attributeName)
		{
			string result = string.Empty;

			var node = doc.SelectSingleNode(xpath);
			if(node != null)
			{ result = node.Attributes[attributeName].Value; }

			return result;
		}
Ejemplo n.º 7
0
		public static string GetInnerText(HtmlAgilityPack.HtmlNode doc, string xpath)
		{
			string result = string.Empty;

			var node = doc.SelectSingleNode(xpath);
			if(node != null)
			{ result = node.InnerText.Trim(); }

			return result;
		}
Ejemplo n.º 8
0
            private Vehicle(HtmlAgilityPack.HtmlNode htmlData)
            {
                // parse the html node to get the info out

                string licensePlate = htmlData.SelectSingleNode(".//input[@type='text']/@value")?.GetAttributeValue("value", "");

                string vehicleTypeVal = htmlData.SelectSingleNode(".//select/option[@selected='selected']/@value")?.GetAttributeValue("value", "");

                var hiddenData = htmlData.SelectNodes(".//input[@type='hidden']");
                var hiddenId = hiddenData.Where(input => input.Attributes["name"]?.Value.Contains("VehicleUid") == true)?.First()?.GetAttributeValue("value", "");
                var hiddenLicPlate = hiddenData.Where(input => input.Attributes["name"]?.Value.Contains("LicensePlateHiddenField") == true)?.First()?.GetAttributeValue("value", "");

                _myType = (VehicleType)int.Parse(vehicleTypeVal);
                _myLicensePlate = licensePlate;
                _myHiddenLicensePlate = hiddenLicPlate;
                _myVehicleId = hiddenId;

                WebData = new VehicleWebData(htmlData);
                _isFromWebsite = true;
            }
Ejemplo n.º 9
0
 public override dynamic Select(HtmlAgilityPack.HtmlNode element)
 {
     var node = element.SelectSingleNode(_xpath);
     if (node != null)
     {
         if (HasAttribute())
         {
             return node.Attributes.Contains(_attribute) ? node.Attributes[_attribute].Value?.Trim() : null;
         }
         else
         {
             return node;
         }
     }
     return null;
 }
        /// <summary>
        /// Parses data from an HTML node for a listing items to populate most of the data into a craigslistInfo object
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public static CraigslistInfo transformSummaryHTMLNodeIntoCraigslistInfo(HtmlAgilityPack.HtmlNode item)
        {
            CraigslistInfo craigslistInfo = new CraigslistInfo();            
 
            //
            // the node is a block of HTml that looks like this
            //<p class="row" data-latitude="" data-longitude="">
            //            <span class="ih" id="images:3Ee3K43m25Ne5K95Hecbmc8b000ac1a0e1376.jpg">&nbsp;</span>
            //            <span class="itemdate"> Dec 11</span>
            //            <span class="itemsep"> - </span>
            //            <a href="http://vancouver.en.craigslist.ca/pml/ctd/3427888027.html">2003 HYUNDAI TIBURON GT</a>
            //            <span class="itemsep"> - </span>
            //            <span class="itemph"></span>
            //            <span class="itempp"> $6595</span>
            //            <span class="itempn"><font size="-1"> (MISSION)</font></span>
            //            <span class="itemcg" title="ctd"> <small class="gc"><a href="/ctd/">cars & trucks - by dealer</a></small></span>
            //            <span class="itempx"> <span class="p"> pic</span></span>
            //            <br class="c">
            //        </p>
            //
            // First of all parse the date : Dec 11
            //
            // .:TODO:. this is not working and throwing the exception every time - and using the output in jscript breaks the page!
            //
            string[] formats = { " MMM dd" };
            try
            {
                craigslistInfo.DatePostedReal = DateTime.ParseExact(item.SelectSingleNode("//span[@class='itemdate']").InnerText.Substring(0, formats[0].Length), formats, null, System.Globalization.DateTimeStyles.AssumeUniversal);
            }
            catch (FormatException)
            {
                craigslistInfo.DatePostedReal = DateTime.MinValue;
                Console.WriteLine("Unable to convert '{0}' to a date.", item.SelectSingleNode("//span[@class='itemdate']").InnerText);
            }

            //
            // Next the Price
            //
            craigslistInfo.Price = item.SelectSingleNode("//span[@class='itempp']").InnerText.Trim();
            craigslistInfo.SaleArea = item.SelectSingleNode("//font").InnerText;
            craigslistInfo.LinkURL = item.ChildNodes[7].Attributes["href"].Value;
            craigslistInfo.ShortTitle = item.ChildNodes[7].InnerText;
            craigslistInfo.Category = item.ChildNodes[17].SelectSingleNode("//a").InnerText;
            craigslistInfo.DatePostedParsed = craigslistInfo.DatePostedReal.ToString("dd MMM yyyy HH:mm:ss");
            return craigslistInfo;
        }
Ejemplo n.º 11
0
        private BasicInfo ProcessGameData(HtmlAgilityPack.HtmlNode game, DateTime gameDate, string webID)
        {
            // 建立比賽資料,時間以台灣為主
            BasicInfo gameInfo = new BasicInfo(this.AllianceID, this.GameType, gameDate, webID);
            gameInfo.Away = game.SelectSingleNode("div/div[@class='team visitor']/div[@class='team-capsule']/p[@class='team-name']/span/a").InnerText;
            gameInfo.Home = game.SelectSingleNode("div/div[@class='team home']/div[@class='team-capsule']/p[@class='team-name']/span/a").InnerText;
            gameInfo.Status = game.SelectSingleNode("div/div[@class='game-header']/div/p").InnerText;
            gameInfo.Status = gameInfo.Status.ToLower();
            // 取代文字
            gameInfo.Status = gameInfo.Status.Replace("halftime", "中場休息");
            gameInfo.Status = gameInfo.Status.Replace("half", "中場休息");
            gameInfo.Status = gameInfo.Status.Replace("qtr", "");
            gameInfo.Status = gameInfo.Status.Replace("1st", "");
            gameInfo.Status = gameInfo.Status.Replace("2nd", "");
            gameInfo.Status = gameInfo.Status.Replace("3rd", "");
            gameInfo.Status = gameInfo.Status.Replace("4th", "");
            gameInfo.Status = gameInfo.Status.Replace("ot", "");
            gameInfo.Status = gameInfo.Status.Replace("2ot", "");
            gameInfo.Status = gameInfo.Status.Replace("of", "");
            gameInfo.Status = gameInfo.Status.Replace("end", "結束");
            gameInfo.Status = gameInfo.Status.Replace("&nbsp;", "");//移除空白字元
            gameInfo.Status = gameInfo.Status.Trim();

            if (gameInfo.Status == "00:00") gameInfo.Status = "結束";

            //目前有顯示的分數欄位

            HtmlAgilityPack.HtmlNode scoreHeader = game.SelectSingleNode("div/div[@class='game-header']/ul[@class='score header']");
            if (scoreHeader != null)//是否已經有比分
            {
                string linescoreHeader = game.SelectSingleNode("div/div[@class='game-header']/ul[@class='score header']").InnerText;
                if (linescoreHeader.Length > 7)//資料不完整,缺乏前面局數比分     2 3 4 OT OT T
                {
                    //第1個數字才是有顯示的比分
                    int lossInning = 1;
                    int.TryParse(linescoreHeader.Substring(0, 1), out lossInning);
                    if (lossInning > 1)
                    {
                        lossInning--;
                        GetGameScore(gameInfo, lossInning);//無暫存取得遺漏比分
                    }
                }

                List<int> FullAwayBoard = new List<int>();//完整比分
                List<int> FullHomeBoard = new List<int>();//完整比分
                if (this.DownScore.ContainsKey(webID) && !string.IsNullOrEmpty(this.DownScore[webID].Data))
                {
                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    doc.LoadHtml(this.DownScore[webID].Data);

                    HtmlAgilityPack.HtmlNodeCollection HomeAway = doc.GetElementbyId("gamepackageTop").SelectNodes("div[@class='line-score clear']/div[@class='line-score-container']/table/tr");
                    if (HomeAway != null && HomeAway.Count == 3)
                    {
                        foreach (HtmlAgilityPack.HtmlNode scores in HomeAway)
                        {
                            if (scores.Attributes["class"] != null)//忽略periods
                                continue;

                            HtmlAgilityPack.HtmlNodeCollection score = scores.SelectNodes("td");
                            if (score != null)
                            {
                                bool isAway = false;
                                if (FullAwayBoard.Count == 0)
                                    isAway = true;

                                int period = score.Count - 1;
                                for (int i = 1; i < period; i++)//第0個值為隊名
                                {
                                    string tmpNum = score[i].InnerHtml.Replace("\n", "").Replace("\t", "").Trim();
                                    int tryInt = 0;
                                    int.TryParse(tmpNum, out tryInt);

                                    if (isAway)
                                        FullAwayBoard.Add(tryInt);
                                    else
                                        FullHomeBoard.Add(tryInt);
                                }
                            }
                        }
                    }
                }

                //首頁比分計算
                foreach (HtmlAgilityPack.HtmlNode numDoc in game.SelectNodes("div/div[@class='team visitor']/ul[@class='score']/li"))
                {
                    int num = 0;
                    if (int.TryParse(numDoc.InnerText, out num))
                    {
                        if (gameInfo.AwayBoard.Count < 4)//沒有OT
                            gameInfo.AwayBoard.Add(numDoc.InnerText);
                        else
                        {
                            int otDiff = FullAwayBoard.Count - gameInfo.AwayBoard.Count;//OT數差別
                            if (FullAwayBoard.Count == 0 || otDiff == 0)
                                gameInfo.AwayBoard.Add(numDoc.InnerText);
                            else
                            {
                                int sum = 0;
                                for (int i = 0; i < otDiff - 1; i++)
                                {
                                    sum += FullAwayBoard[4 + i];//最後一個OT不累加
                                    gameInfo.AwayBoard.Add(FullAwayBoard[4 + i].ToString());//OT1 OT2 OT3 ...
                                }

                                gameInfo.AwayBoard.Add((num - sum).ToString());//剩下的OT分數
                            }
                        }
                    }
                }

                foreach (HtmlAgilityPack.HtmlNode numDoc in game.SelectNodes("div/div[@class='team home']/ul[@class='score']/li"))
                {
                    int num = 0;
                    if (int.TryParse(numDoc.InnerText, out num))
                    {
                        if (gameInfo.HomeBoard.Count < 4)//沒有OT
                            gameInfo.HomeBoard.Add(numDoc.InnerText);
                        else
                        {
                            int otDiff = FullHomeBoard.Count - gameInfo.HomeBoard.Count;//OT數差別
                            if (FullHomeBoard.Count == 0 || otDiff == 0)//尚未取得完整比分資料 或者是最後一個比分則為總分
                                gameInfo.HomeBoard.Add(numDoc.InnerText);
                            else
                            {
                                int sum = 0;
                                for (int i = 0; i < otDiff - 1; i++)
                                {
                                    sum += FullHomeBoard[4 + i];//最後一個OT不累加
                                    gameInfo.HomeBoard.Add(FullHomeBoard[4 + i].ToString());//OT1 OT2 OT3 ...
                                }

                                gameInfo.HomeBoard.Add((num - sum).ToString());//剩下的OT分數
                            }
                        }
                    }
                }
                // 總分
                if (gameInfo.AwayBoard.Count > 0)
                {
                    gameInfo.AwayPoint = gameInfo.AwayBoard[gameInfo.AwayBoard.Count - 1];
                    gameInfo.AwayBoard.RemoveAt(gameInfo.AwayBoard.Count - 1);
                    gameInfo.HomePoint = gameInfo.HomeBoard[gameInfo.HomeBoard.Count - 1];
                    gameInfo.HomeBoard.RemoveAt(gameInfo.HomeBoard.Count - 1);
                }
            }

            if (gameInfo.Status.IndexOf("final") != -1)
            {
                gameInfo.GameStates = "E";
            }
            else if (gameInfo.Quarter > 0)
            {
                gameInfo.GameStates = "S";
            }

            return gameInfo;
        }
Ejemplo n.º 12
0
            public VehicleWebData(HtmlAgilityPack.HtmlNode vehicleData)
            {
                var allInputs = vehicleData.SelectNodes(".//input");
                var select = vehicleData.SelectSingleNode(".//select");

                LicensePlateTextBox = allInputs.Where(input => input.Attributes["name"]?.Value?.Contains("LicensePlateTextBox") == true).First()?.GetAttributeValue("name", "");
                LicensePlateHiddenField = allInputs.Where(input => input.Attributes["name"]?.Value?.Contains("LicensePlateHiddenField") == true).First()?.GetAttributeValue("name", "");
                VehicleUidHiddenField = allInputs.Where(input => input.Attributes["name"]?.Value?.Contains("VehicleUidHiddenField") == true).First()?.GetAttributeValue("name", "");
                VehicleTypeHiddenField = allInputs.Where(input => input.Attributes["name"]?.Value?.Contains("VehicleTypeUidHiddenField") == true).First()?.GetAttributeValue("name", "");
                VehicleTypeDropDown = select?.GetAttributeValue("name", "");
            }
        public ResultType_enum FillCustomer(Customer customer, HtmlAgilityPack.HtmlNode customerNode, InternetRequestEngine internetRequestEngine,
                               out string message)
        {
            try
            {
                message = "";
                HtmlAgilityPack.HtmlNode nodeTmp = null;

                #region Определение параметров
                text = ".//table";
                //text += "/tbody"; !!!newBrowser
                text += "/tr";
                text += "/td[@class=\"descriptTenderTd\"]";
                text += "/dl";
                text += "/dt";
                text += "/a";

                nodeTmp = customerNode.SelectSingleNode(text);

                // Название заказчика
                if (nodeTmp.Attributes.Contains("title"))
                    customer.Name = Globals.DecodeInternetSymbs(nodeTmp.Attributes["title"].Value.Trim());

                // Определение ID 94 и 223 законов
                // Есди существует атрибут <href>, значит указана одна ссылка на один закон
                LawType_enum lawType = LawType_enum.None;
                Regex regex = new Regex(@"http://.*?Id=\d*");
                MatchCollection matchColl = null;
                if (nodeTmp.Attributes.Contains("href"))
                {
                    matchColl = regex.Matches(nodeTmp.Attributes["href"].Value);
                }
                else
                {
                    matchColl = regex.Matches(nodeTmp.Attributes["onclick"].Value);
                }

                foreach (Match match in matchColl)
                {
                    string lawID = GetIDLaw(match.Value, out lawType);
                    switch (lawType)
                    {
                        case (LawType_enum._44_94):
                            customer.Law_44_94_ID = lawID;
                            break;
                        case (LawType_enum._223):
                            customer.Law_223_ID = lawID;
                            break;
                        default:
                            break;
                    }

                    //break;
                }

                // Уровень организации
                text = ".//table";
                //text += "/tbody"; !!!newBrowser
                text += "/tr";
                text += "/td[@class=\"tenderTd\"]";
                text += "/dl";
                text += "/dt";

                nodeTmp = customerNode.SelectSingleNode(text);
                CustomerLevel_enum customerLevel = CustomerLevel_enum.None;
                if (nodeTmp != null) {
                    switch(nodeTmp.InnerText.ToLower().Trim()) {
                        case ("федеральный уровень"):
                            customerLevel = CustomerLevel_enum.Federal;
                            break;
                        case ("уровень субъекта рф"):
                            customerLevel = CustomerLevel_enum.Subject;
                            break;
                        case ("муниципальный уровень"):
                            customerLevel = CustomerLevel_enum.Municipal;
                            break;
                        case ("иное"):
                            customerLevel = CustomerLevel_enum.Other;
                            break;
                    }
                }
                customer.CustomerLevel = mvm.wc.CustomerLevels.FirstOrDefault(m => m.CustomerLevelCode == customerLevel.ToString());

                // ИНН (VATIN)
                text = ".//table";
                //text += "/tbody"; !!!newBrowser
                text += "/tr";
                text += "/td[@class=\"descriptTenderTd\"]";
                text += "/dl";
                text += "/dd[@class=\"nameOrganization\"]";
                text += "/span";

                HtmlAgilityPack.HtmlNodeCollection collectionVatin = customerNode.SelectNodes(text);
                foreach (HtmlAgilityPack.HtmlNode nodeVatin in collectionVatin)
                {
                    int vatinIntPos = nodeVatin.InnerText.IndexOf("ИНН:");
                    if (vatinIntPos > -1)
                    {
                        customer.Vatin = nodeVatin.InnerText.Substring(vatinIntPos + 4, nodeVatin.InnerText.Length - (vatinIntPos + 4)).Trim();
                        break;
                    }
                }

                // Адрес
                text = ".//table";
                //text += "/tbody"; !!!newBrowser
                text += "/tr";
                text += "/td[@class=\"descriptTenderTd\"]";
                text += "/dl";
                text += "/dd";

                HtmlAgilityPack.HtmlNodeCollection adressDDColl = customerNode.SelectNodes(text);
                if (adressDDColl.Count == 3)
                {
                    customer.Address = Globals.CutAddress(adressDDColl[2].InnerText.Trim());
                }
                #endregion

                return ResultType_enum.Done;
            }
            catch (Exception ex)
            {
                message = ex.Message + "\n\n" + ex.StackTrace;
                return ResultType_enum.Error;
            }
        }
Ejemplo n.º 14
0
        private static byte[] GetMp3Data(HtmlAgilityPack.HtmlNode htmlNode)
        {
            var anchorNode = htmlNode.SelectSingleNode("a");

            if (anchorNode != null)
            {
                var attr = anchorNode.Attributes.FirstOrDefault(x => x.Name == "href");
                if (attr != null && attr.Value.ToLower().EndsWith("mp3"))
                {
                    using (var mp3Client = new WebClient())
                    {
                        return mp3Client.DownloadData(attr.Value);
                    }
                }
            }

            return null;
        }