当前位置: 首页>>代码示例>>C#>>正文


C# HtmlAgilityPack.HtmlDocument.GetElementbyId方法代码示例

本文整理汇总了C#中HtmlAgilityPack.HtmlDocument.GetElementbyId方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlAgilityPack.HtmlDocument.GetElementbyId方法的具体用法?C# HtmlAgilityPack.HtmlDocument.GetElementbyId怎么用?C# HtmlAgilityPack.HtmlDocument.GetElementbyId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HtmlAgilityPack.HtmlDocument的用法示例。


在下文中一共展示了HtmlAgilityPack.HtmlDocument.GetElementbyId方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LoadContent

        private async Task LoadContent(DataItem _item)
        {
            string contentStr = string.Empty;
            try
            {
                contentStr = await Define.DownloadStringAsync(_item.Link);
            }
            catch (Exception ex)
            {

                //throw;
            }

            if (contentStr != string.Empty)
            {
                HtmlAgilityPack.HtmlDocument htmlDoc = new HtmlAgilityPack.HtmlDocument();
                htmlDoc.LoadHtml(contentStr);

                HtmlAgilityPack.HtmlNode htmlNode = htmlDoc.GetElementbyId("ContentContainer");
                while (htmlNode.Descendants("script").Count() > 0)
                {
                    htmlNode.Descendants("script").ElementAt(0).Remove();
                }
                while (htmlNode.Descendants("meta").Count() > 0)
                {
                    htmlNode.Descendants("meta").ElementAt(0).Remove();
                }

                //contentStr = "<p><i>This blog post was authored by Andrew Byrne (<a href=\"http://twitter.com/AndrewJByrne\" target=\"_blank\">@AndrewJByrne</a>), a Senior Content Developer on the Windows Phone Developer Content team.</i> <p><i></i> <p><i>- Adam</i></p> <hr>  <p> <table cellspacing=\"1\" cellpadding=\"2\" width=\"722\" border=\"0\"> <tbody> <tr> <td valign=\"top\" width=\"397\"> <p>The Windows Phone Developer Content team is continually adding new code samples that you can download from MSDN. In this post, we introduce you to the 10 latest samples that we’ve posted on MSDN. Each sample includes a readme file that walks you through building and running the sample, and includes links to relevant, related documentation. We hope these samples help you with your app development and we look forward to providing more samples as we move forward. You can check out all of our <a href=\"http://code.msdn.microsoft.com/wpapps/site/search?f%5B0%5D.Type=Contributors&amp;f%5B0%5D.Value=Windows%20Phone%20SDK%20Team&amp;f%5B0%5D.Text=Windows%20Phone%20SDK&amp;sortBy=Date\" target=\"_blank\">samples on MSDN</a>.</p></td> <td valign=\"top\" width=\"320\"> <p><a href=\"http://blogs.windows.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-53-84-metablogapi/clip_5F00_image002_5F00_1765A66A.png\"><img title=\"clip_image002\" style=\"border-top: 0px; border-right: 0px; background-image: none; border-bottom: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; border-left: 0px; display: block; padding-right: 0px; margin-right: auto\" border=\"0\" alt=\"clip_image002\" src=\"http://blogs.windows.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-53-84-metablogapi/clip_5F00_image002_5F00_thumb_5F00_7B083E7C.png\" width=\"121\" height=\"213\"></a></p></td></tr></tbody></table></p> <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=306704\" target=\"_blank\">Stored Contacts Sample</a></h3> <p>This sample illustrates how to use the <a href=\"http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.phone.personalinformation.contactstore(v=vs.105).aspx\" target=\"_blank\">ContactStore</a> class and related APIs to create a contact store for your app. This feature is useful if your app uses an existing cloud-based contact store. You can use the APIs you to create contacts on the phone that represent the contacts in your remote store. You can display and modify the contacts in the People Hub on your phone, just like contacts that are added through the built-in experience. You can use the APIs to update and delete contacts you have created on the phone and also to query for any changes the user has made to the contacts locally so you can sync those changes to your remote store. <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=306701\" target=\"_blank\">Basic Storage Recipes</a></h3> <p>This is a “Windows Runtime Storage 101” sample for Windows Phone developers moving from isolated storage and <b>System.IO</b> to <a href=\"http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.storage.aspx\" target=\"_blank\">Windows.Storage</a> and <a href=\"http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.storage.streams.aspx\" target=\"_blank\">Windows.Storage.Streams</a>. The sample demonstrates how to write to and read files, in addition to how to enumerate directory trees. It also demonstrates how to pass data from one page to the next, and how to persist application state when the app is deactivated. <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=301509\" target=\"_blank\">Trial Experience Sample</a></h3> <p>This sample shows you how to design your app to detect its license state when the app launches, and how to detect changes to the license state while running. It comes with a helper class that you can use in your app to wrap <a href=\"http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.applicationmodel.store.licenseinformation.aspx\" target=\"_blank\">LicenseInformation</a> functionality. <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=302059\" target=\"_blank\">Windows Runtime Component Sample</a></h3> <p>This sample demonstrates the basics of creating a Windows Phone Runtime component in C++ and consuming it in a XAML app. The sample demonstrates three scenarios: the first scenario illustrates how to call synchronous and asynchronous methods to perform a computation. The second scenario uses the same computation component to demonstrate progress reporting and cancellation of long-running tasks. Finally, the third scenario shows how to use a component to wrap logic that uses <a href=\"http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj206944(v=vs.105).aspx\" target=\"_blank\">XAudio2 APIs</a> to play a sound. <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=306097\" target=\"_blank\">Company Hub Sample</a></h3> <p>This sample demonstrates the construction of an app that is capable of deploying line-of-business (LOB) apps to employees of a corporation. The sample uses an example XML file to define the company XAPs that are available to employees for secure download, and shows you how to dynamically access that file at run time. Then it shows you how to install company apps, enumerate the apps, and then launch the installed company apps. This app is just an example framework and requires additional work beyond the sample to be functional. <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=306702\" target=\"_blank\">Image Recipes</a></h3> <p>This sample illustrates how to use images in your app efficiently, while giving your users a great experience. It tackles downsampling images, implementing pinch and zoom, and downloading images with a progress display and an option to cancel the download. We’ve taken a recipe approach: each recipe is delivered in a self-contained page in the app so you can focus your attention on the particular part of the sample you are most interested in.  <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=306026\" target=\"_blank\">Azure Voice Notes</a></h3> <p>This sample uses Windows Phone speech recognition APIs and Windows Azure Mobile Services to record voice notes as text and store the notes in the cloud. It shows how Mobile Services can be used to authenticate a user with their Microsoft Account. It also demonstrates how to use Mobile Services to store, retrieve, and delete data from an Azure database table. The app generates text from speech using the Windows Phone speech recognition APIs and the phone’s predefined dictation grammar. <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=299241\" target=\"_blank\">Kid's Corner Sample</a></h3> <p>This sample illustrates how to use the <a href=\"http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.phone.applicationmodel.applicationprofile.modes(v=vs.105).aspx\" target=\"_blank\">ApplicationProfile.Modes</a> property to recognize Kid’s Corner mode. When the app runs, it checks the <a href=\"http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.phone.applicationmodel.applicationprofile.modes(v=vs.105).aspx\" target=\"_blank\">ApplicationProfile.Modes</a> property. If the value is <b>ApplicationProfileModes.Alternate</b>, you’ll know that the app is running in Kid’s Corner mode. Depending on the content of your app, you may want to change its appearance or features when it runs in Kid’s Corner mode. Some features that you should consider disabling when running in Kid’s Corner mode include in-app purchases, launching the web browser, and the ad control. <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=267468\" target=\"_blank\">URI Association Sample</a></h3> <p>Use this sample to learn how to automatically launch your app via URI association. This sample includes three apps: a URI launcher, and two apps that handle the URI schemes that are built in to the launcher app. You can launch an app that is included with the sample or edit the URI and launch a different app. There is also a button for launching a URI on another phone using Near Field Communication (NFC).  <h3><a href=\"http://go.microsoft.com/fwlink/?LinkId=275007\" target=\"_blank\">Speech for Windows Phone: Speech recognition using a custom grammar</a></h3> <p>A grammar defines the words and phrases that an app will recognize in speech input. This sample shows you how to go beyond the basics to create a powerful grammar (based on the grammar schema) with which your app can recognize commands and phrases constructed in different ways. <p>&nbsp; <p>This post is just a glimpse of the latest Windows Phone samples we’ve added to the MSDN code gallery. From launching apps with URI associations, to dictating notes and storing them in the cloud, we hope that there’s something for everyone. We’ll be sure to keep you posted as new samples are added to the collection, so stay tuned. In the meantime, grab the samples, experiment with them, and use the code to light up your apps. You can download all Windows Phone samples at <a href=\"http://code.msdn.microsoft.com/wpapps\" target=\"_blank\">http://code.msdn.microsoft.com/wpapps</a>. <div style=\"clear:both;\"></div><img src=\"http://blogs.windows.com/aggbug.aspx?PostID=588575&AppID=5384&AppType=Weblog&ContentType=0\" width=\"1\" height=\"1\">";
                Items[Items.IndexOf(_item)].Content = htmlNode.InnerHtml.Replace("\r", "").Replace("\n", "");
            }
        }
开发者ID:nhannguyen2204,项目名称:VnFeeds_Win8,代码行数:32,代码来源:ItemDetailViewModel.cs

示例2: button2_Click

        private void button2_Click(object sender, EventArgs e)
        {
            // get HTML content from website
            string HTML;
            using (var wc = new WebClient())
            {
                HTML = wc.DownloadString("http://www.gagangiri.org/teachings.html");
            }

            // create HtmlAgilityPack document object from HTML
            var doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(HTML);

            // pasing HTML
            label1.Text = "City: " + doc.GetElementbyId("city").InnerText;
        }
开发者ID:vearvindkumar,项目名称:Scrapper,代码行数:16,代码来源:Form1.cs

示例3: ValidateTable

        private void ValidateTable(ValidationEventArgs e)
        {
            var doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(e.Response.BodyString);

            var table = doc.GetElementbyId(TableId);

            if (table == null)
            {
                Fail(e, String.Format("Could not locate a table tag named '{0}'!", TableId));
            }
            else if (table.Name != "table")
            {
                Fail(e, String.Format("Found a tag named '{0}' but it wasn't a table!", TableId));
            }
            else
            {
                ValidateTable(e, table);
            }
        }
开发者ID:rderouin,项目名称:test.utilities,代码行数:20,代码来源:TableColumnValueValidator.cs

示例4: Follow

        public override int Follow()
        {
            // 沒有資料就離開
            if (string.IsNullOrEmpty(this.DownHome.Data)) return 0;

            int result = 0;
            BasicInfo gameInfo = null;
            HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();

            // 載入資料
            document.LoadHtml(this.DownHome.Data);
            //document.Load(@"C:\Users\Administrator\Desktop\ahl.txt");//本機資料測試
            // 資料位置
            //string xPath = "/html[1]/body[1]/div[1]/div[3]/div[1]/div[1]/div[2]/div[3]";
            //HtmlAgilityPack.HtmlNode nodeGames = document.DocumentNode.SelectSingleNode(xPath);

            HtmlAgilityPack.HtmlNode nodeGames = document.GetElementbyId("AHLscoreBox");
            // 判斷資料
            if (nodeGames != null && nodeGames.ChildNodes != null)
            {
                DateTime gameDate = this.GameDate;
                DateTime gameTime = this.GameDate;
                //string gameDateStr = null;
                int gameQuarter = 0;
                // 資料
                foreach (HtmlAgilityPack.HtmlNode game in nodeGames.ChildNodes)
                {

                    string webID = null;
                    #region 跟盤 ID
                    HtmlAgilityPack.HtmlNodeCollection GameDateInfo = game.SelectNodes("div[@class='final-hd-link']/a");
                    if (GameDateInfo != null && GameDateInfo.Count > 0)
                    {

                        var href = GameDateInfo[0].GetAttributeValue("href", "");
                        if (string.IsNullOrEmpty(href))//取到空值
                            continue;

                        try
                        {
                            if (!href.Contains("http"))
                                href = "http://" + href;

                            Uri uri = new Uri(href);
                            // 判斷是否有資料
                            if (uri.Query != null && !string.IsNullOrEmpty(uri.Query))
                            {
                                HttpRequest req = new HttpRequest("", uri.AbsoluteUri, uri.Query.Substring(1));
                                // 判斷資料
                                if (req["game_id"] != null && !string.IsNullOrEmpty(req["game_id"].Trim()))//已開賽
                                {
                                    webID = req["game_id"];
                                }
                                else if (req["file_path"] != null && !string.IsNullOrEmpty(req["file_path"].Trim()))//未開賽
                                {
                                    webID = req["file_path"];
                                    if (webID.IndexOf("/") != -1)
                                    {
                                        webID = webID.Substring(webID.IndexOf("/") + 1).Trim();
                                    }
                                    if (webID.IndexOf("-") != -1)
                                    {
                                        webID = webID.Substring(0, webID.IndexOf("-")).Trim();
                                    }
                                }
                            }
                        }
                        catch { }

                    }
                    else
                        continue;

                    // 沒有跟盤 ID 就往下處理
                    if (webID == null || string.IsNullOrEmpty(webID.Trim())) continue;
                    #endregion

                    // 建立比賽資料,時間以台灣為主
                    DateTime GameTime;
                    if (diffTime > 0)
                        GameTime = this.GameDate.AddHours(diffTime);
                    else
                    {
                        TimeSpan ts = DateTime.Now - this.GameDate;
                        GameTime = this.GameDate.AddHours(ts.TotalHours);
                    }

                    gameInfo = null;
                    gameInfo = new BasicInfo(this.AllianceID, this.GameType, GameTime, webID);
                    gameQuarter = 0;

                    #region 處理比賽資料
                    #region 狀態
                    gameInfo.Status = game.ChildNodes[1].InnerText.ToLower().Trim();
                    gameInfo.Status = gameInfo.Status.ToLower().Trim();
                    // 判斷目前局數
                    if (gameInfo.Status.IndexOf("1st") != -1) gameQuarter = 1;
                    if (gameInfo.Status.IndexOf("2nd") != -1) gameQuarter = 2;
                    if (gameInfo.Status.IndexOf("3rd") != -1) gameQuarter = 3;
                    if (gameInfo.Status.IndexOf("ot") != -1) gameQuarter = 4;
//.........这里部分代码省略.........
开发者ID:chanhan,项目名称:ap_follow,代码行数:101,代码来源:IhAHL.cs

示例5: DisplayResults

        public static string DisplayResults()
        {
            string scope = HostingEnvironment.MapPath("~");

            Regex regex = new Regex(@"([a-fA-F0-9]{64})");
            string connectionString = "Provider=Search.CollatorDSO;Extended Properties=\"Application=Windows\"";
            HashSet<string> imgExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
                {
                    ".jpg", ".jpeg", ".jpe", ".gif", ".png", ".tiff", ".tif", ".svg", ".svgz", ".xbm", ".bmp", ".ico"
                };

            OleDbConnection connection = new OleDbConnection(connectionString);

            string query = @"SELECT TOP 100 System.ItemFolderPathDisplay FROM SystemIndex WHERE scope ='file:" + scope + "' AND System.FileName = 'index.htm' ORDER BY System.DateModified DESC";
            OleDbCommand command = new OleDbCommand(query, connection);
            connection.Open();
            HashSet<string> result = new HashSet<string>();
            OleDbDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                string searchString = reader.GetString(0);
                Match match = regex.Match(searchString);
                if (match.Success)
                {
                    result.Add(match.Value);
                }
            }
            connection.Close();
            if (result.Count > 0)
            {
                string searchHTML = "";
                var uniqueResults = result.Distinct();
                foreach (string s in uniqueResults)
                {
                    var signature = "";
                    var img = "";
                    //var file = "";
                    var msg = "";
                    var date = "";
                    var blockchain = "";
                    var profiles = "";
                    var doc = new HtmlAgilityPack.HtmlDocument();
                    try
                    {
                        doc.Load(scope + s + "\\index.htm");
                    }
                    catch { break; }


                    try
                    {
                        img = doc.GetElementbyId("img0").InnerText;
                        searchHTML = searchHTML + "<div class=\"item\"><div class=\"content\"><table><tr><th rowspan=\"6\"><a href=\"" + s + "/index.htm\"><img src=\"" + s + "/" + img + "\" /></a></th><th></th></tr>";
                    }
                    catch { searchHTML = searchHTML + "<div class=\"item\"><div class=\"content\"><table><tr><th rowspan=\"6\"></th><th></th></tr>"; }
                    try { signature = doc.GetElementbyId("signature").InnerText; }
                    catch { }
                    try { blockchain = doc.GetElementbyId("blockchain").InnerText; }
                    catch { }
                    searchHTML = searchHTML + "<tr><td>" + blockchain + " - " + signature + "</td></tr>";
                    try { date = doc.GetElementbyId("block-date").InnerText; }
                    catch { }
                    try { msg = doc.GetElementbyId("msg1").InnerText; }
                    catch { }
                    try { profiles = doc.GetElementbyId("profiles").InnerHtml; }
                    catch { }
                    searchHTML = searchHTML + "<tr><td><a href=\"" + s + "/index.htm\">" + msg.PadRight(50).Substring(0, 49) + "</a></td></tr>";

                    if (msg.Length > 500)
                    { searchHTML = searchHTML + "<tr><td>" + date + " : " + msg.Substring(0, 499) + "...</td></tr>"; }
                    else { searchHTML = searchHTML + "<tr><td>" + date + " : " + msg + "</td></tr>"; }

                    if (profiles.Length > 0)
                    {
                        searchHTML = searchHTML + "<tr><td>" + profiles + "</td></tr>";
                    }
                    searchHTML = searchHTML + "<tr><td><a href=\"" + s + "/index.htm\"><font size=\"1\">" + s + "</font></a></td></tr></table></div></div>";

                }
                return searchHTML;

            }
            else
            { return "<div class=\"item\"><div class=\"content\">Nothing found</div></div>"; }
        
        }
开发者ID:embiimob,项目名称:bitFossil,代码行数:86,代码来源:recent.aspx.cs

示例6: FollowByWeb

        private int FollowByWeb()
        {
            // 沒有資料就離開
            if (string.IsNullOrEmpty(this.DownHome.Data)) return 0;

            int result = 0;
            BasicInfo gameInfo = null;
            HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
            //string xPath = "/html[1]/body[1]/div[1]/div[2]/div[3]/div[8]/table[1]";
            // 載入資料
            document.LoadHtml(this.DownHome.Data);
            // 資料位置
            HtmlAgilityPack.HtmlNode contentNode = document.GetElementbyId("contents");
            if (contentNode == null) { return 0; }

            HtmlAgilityPack.HtmlNode nodeGames = contentNode.SelectSingleNode("//div[contains(@class,'NpbSchedule')]/table");

            // 判斷資料
            if (nodeGames != null && nodeGames.ChildNodes != null)
            {
                DateTime gameDate = this.GameDate;
                DateTime gameTime = this.GameDate;
                string gameDateStr = null;

                // 資料
                foreach (HtmlAgilityPack.HtmlNode game in nodeGames.ChildNodes)
                {
                    // 不是資料就往下處理
                    if (game.Name != "tr") continue;

                    string webID = null;
                    string webUrl = null;
                    string webStatus = null;
                    int timeIndex = 8;
                    int idIndex = 6;
                    int awayIndex = 0;
                    int homeIndex = 4;

                    #region 取得日期
                    if (game.ChildNodes.Count == 15)
                    {
                        gameDateStr = game.ChildNodes[1].InnerText.Replace("月", "/").Replace("日", "").Trim();
                        // 截斷日期
                        if (gameDateStr.IndexOf("(") != -1)
                            gameDateStr = DateTime.Now.ToString("yyyy") + "/" + gameDateStr.Substring(0, gameDateStr.IndexOf("(")).Trim();
                        // 判斷日期,失敗就往下處理
                        if (!DateTime.TryParse(gameDateStr, out gameDate))
                        {
                            gameDateStr = null;
                            continue;
                        }
                        timeIndex = 11;
                        idIndex = 9;
                        awayIndex = 3;
                        homeIndex = 7;
                    }
                    // 沒有日期就往下處理
                    if (string.IsNullOrEmpty(gameDateStr)) continue;
                    // 錯誤的陣列就往下處理
                    if (timeIndex >= game.ChildNodes.Count) continue;
                    #endregion
                    #region 取得時間
                    // 判斷日期,錯誤就離開
                    string timeStr = game.ChildNodes[timeIndex].InnerText;
                    // 取出資料
                    timeStr = timeStr.Substring(0, timeStr.IndexOf(" "));
                    if (!DateTime.TryParse(gameDate.ToString("yyyy/MM/dd") + " " + timeStr, out gameTime)) continue;
                    // 判斷是否為今天,不是今天就往下處理
                    if (this.GameDate.Date != gameTime.Date)
                    {
                        gameDateStr = null;
                        continue;
                    }
                    #endregion
                    #region 跟盤 ID
                    webID = game.ChildNodes[idIndex].ChildNodes[0].GetAttributeValue("href", "");
                    webStatus = game.ChildNodes[idIndex].ChildNodes[0].InnerText;
                    Uri uri = null;
                    // 錯誤處理
                    try
                    {
                        uri = new Uri(@"http://www.a.com" + webID);
                        // 判斷是否有資料
                        if (uri.Segments.Length == 4)
                        {
                            webID = uri.Segments[3].Replace("/", "");
                            if (webStatus == "中止")
                            {
                                webUrl = string.Format(sWebUrl5, webID);
                            }
                            else
                            {
                                webUrl = string.Format(sWebUrl6, webID);
                            }
                        }
                    }
                    catch { webID = null; } // 錯誤,清除跟盤 ID
                    // 沒有跟盤 ID 就往下處理
                    if (webID == null || string.IsNullOrEmpty(webID.Trim()))
                    {
//.........这里部分代码省略.........
开发者ID:chanhan,项目名称:ap_follow,代码行数:101,代码来源:BbNPB.cs

示例7: ProcessGameData

        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++)
                                {
//.........这里部分代码省略.........
开发者ID:chanhan,项目名称:ap_follow,代码行数:101,代码来源:BkWNBA.cs

示例8: GetDescription

        private string GetDescription(HtmlAgilityPack.HtmlDocument Html)
        {
            var description = Html.GetElementbyId("productDescription");

            if (description == null)
            {
                try
                {
                    description = Html.GetElementbyId("pd-available").NextSibling.NextSibling;

                    string javatoparse = description.InnerText;

                    var frame = GetJavaIFrame(javatoparse);

                    var htmlcode = WebUtility.UrlDecode(frame);

                    HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
                    doc.LoadHtml(htmlcode);

                    description = doc.GetElementbyId("productDescription");

                }
                catch (Exception)
                {

                }

            }

            var descriptiontext = "";

            if (description != null)
            {
                descriptiontext = description.InnerText;
            }

            return descriptiontext;
        }
开发者ID:Neil19533,项目名称:AParser,代码行数:38,代码来源:AZonController.cs

示例9: Follow

        public override int Follow()
        {
            // 沒有資料就離開
            if (string.IsNullOrEmpty(this.DownHome.Data)) return 0;

            int result = 0;
            BasicInfo gameInfo = null;
            //HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
            //string xPath = "/html[1]/body[1]/div[1]/div[2]/div[1]/div[6]";
            //// 載入資料
            //document.LoadHtml(this.DownHome.Data);
            // 資料位置
            //HtmlAgilityPack.HtmlNode nodeGames = document.DocumentNode.SelectSingleNode(xPath);

            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(this.DownHome.Data);
            HtmlAgilityPack.HtmlNode nodeGames = doc.GetElementbyId("calendarWrap");
            // 判斷資料
            if (nodeGames != null && nodeGames.ChildNodes != null)
            {
                DateTime gameDate = this.GameDate;
                DateTime gameTime = this.GameDate;
                // 資料
                foreach (HtmlAgilityPack.HtmlNode gameRow in nodeGames.ChildNodes)
                {
                    // 不是資料就往下處理
                    if (gameRow.Name != "div") continue;
                    if (gameRow.GetAttributeValue("class", "").IndexOf("nogame") != -1) continue;

                    HtmlAgilityPack.HtmlNode table = gameRow.ChildNodes[1].ChildNodes[3];
                    // 資料
                    for (int tr = 1; tr < table.ChildNodes.Count; tr += 2)
                    {
                        string webID = null;
                        string webUrl = null;
                        int td = 1;

                        #region 取得日期
                        if (tr == 1)
                        {
                            string dateStr = table.ChildNodes[tr].ChildNodes[1].ChildNodes[1].ChildNodes[0].InnerText.Replace(".", "/");
                            // 日期錯誤就離開
                            if (!DateTime.TryParse(gameDate.ToString("yyyy/") + " " + dateStr, out gameDate))
                            {
                                break;
                            }
                            td += 2;
                        }
                        #endregion

                        // 資料錯誤就往下處理
                        if (table.ChildNodes[tr].ChildNodes[td + 2].ChildNodes.Count != 10) continue;

                        #region 取得時間
                        string timeStr = table.ChildNodes[tr].ChildNodes[td].InnerText;
                        // 時間錯誤就離開
                        if (!DateTime.TryParse(gameDate.ToString("yyyy/MM/dd") + " " + timeStr, out gameTime)) break;
                        #endregion
                        #region 跟盤 ID
                        if (table.ChildNodes[tr].ChildNodes[td + 4].ChildNodes[1].ChildNodes.Count < 2)
                        {
                            // 沒有跟盤 ID,比賽是中止
                            webID = "P" + table.ChildNodes[tr].ChildNodes[td + 2].ChildNodes[0].InnerText
                                        + table.ChildNodes[tr].ChildNodes[td + 2].ChildNodes[8].InnerText;
                        }
                        else
                        {
                            if (table.ChildNodes[tr].ChildNodes[td + 4].ChildNodes[1].ChildNodes[7].Name.ToLower()=="a")
                            {
                                webID = table.ChildNodes[tr].ChildNodes[td + 4].ChildNodes[1].ChildNodes[7].GetAttributeValue("href", "");
                            }
                            else
                            {
                                webID = table.ChildNodes[tr].ChildNodes[td + 4].ChildNodes[1].ChildNodes[3].GetAttributeValue("href", "");
                            }

                            int findFirst = webID.IndexOf("\'");
                            int findLast = webID.LastIndexOf("\'");
                            if (findFirst != -1 && findLast != -1)
                            {
                                findFirst++;
                                webID = webID.Substring(findFirst, findLast - findFirst);
                            }
                            Uri uri = null;
                            HttpRequest req = null;
                            // 錯誤處理
                            try
                            {
                                uri = new Uri(@"http://www.a.com" + webID);
                                // 判斷是否有資料
                                if (uri.Query != null && !string.IsNullOrEmpty(uri.Query))
                                {
                                    req = new HttpRequest("", uri.AbsoluteUri, uri.Query.Substring(1));
                                    // 判斷資料
                                    if (req["gameid"] != null && !string.IsNullOrEmpty(req["gameid"].Trim()))
                                    {
                                        webID = req["gameid"];
                                        // 判斷編號是否為日期
                                        if (DateTime.TryParse(webID.Substring(0, 4) + "/" + webID.Substring(4, 2) + "/" + webID.Substring(6, 2), out gameDate) &&
                                            gameDate.Date == gameTime.Date)
//.........这里部分代码省略.........
开发者ID:chanhan,项目名称:ap_follow,代码行数:101,代码来源:BbKBO.cs

示例10: FinishCompund

 void FinishCompund()
 {
     System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(m_link);
     System.Net.WebResponse response = request.GetResponse();
     System.IO.StringReader reader = new System.IO.StringReader(new System.IO.StreamReader(response.GetResponseStream()).ReadToEnd());
     HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
     document.Load(reader);
     HtmlAgilityPack.HtmlNode mainNode = document.GetElementbyId("p_p_id_dissclinventory_WAR_dissclinventoryportlet_");
     mainNode.SelectSingleNode("/html[1]/body[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[2]/div[1]/table[1]/tbody[1]");
     HtmlAgilityPack.HtmlNode dataNode = mainNode.SelectSingleNode("/html[1]/body[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[2]/div[1]/table[1]/tbody[1]/td[1]/table[2]");
     int numCodes = (dataNode.ChildNodes.Count - 5) / 2;
     m_HazardCodes = new string[numCodes];
     m_HazardTexts = new string[numCodes];
     for (int i = 0; i < numCodes; i++)
     {
         m_HazardTexts[i] = dataNode.ChildNodes[5 + i * 2].ChildNodes[3].InnerText.Trim();
         m_HazardCodes[i] = dataNode.ChildNodes[5 + i * 2].ChildNodes[1].InnerText.Trim();
     }
     HtmlAgilityPack.HtmlNode dsdTableNode = mainNode.SelectSingleNode("/html[1]/body[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[2]/div[2]/div[1]/div[1]/div[2]/div[1]/table[1]/div[1]/div[1]/div[2]/div[1]/table[1]/tbody[1]");
     HtmlAgilityPack.HtmlNode rPhraseNode = dsdTableNode.ChildNodes[1].ChildNodes[3];
     m_rPhrases = rPhraseNode.InnerText.Trim().Split(' ');
     HtmlAgilityPack.HtmlNode sPhraseNode = dsdTableNode.ChildNodes[1].ChildNodes[5];
     m_SPhrases = sPhraseNode.InnerText.Trim().Split(' ');
     HtmlAgilityPack.HtmlNode indicationOfDangerNode = dsdTableNode.ChildNodes[1].ChildNodes[7];
     m_IndicationOfDanger = indicationOfDangerNode.InnerText.Trim().Split(' ');
     finished = true;
 }
开发者ID:wbarret1,项目名称:ChemicalDataSourcesTestApp,代码行数:27,代码来源:EuropeanChemicalInventory.cs

示例11: Grab

        List<Show> Grab(GrabParametersBase p)
        {
            var pp = (GrabParameters)p;

            var url = GetUrl(pp);
            _logger.WriteEntry(string.Format("Grabbing rashut2 {0} for date {1}", pp.Channel, pp.Date.ToString("d")), LogType.Info);
            var wr = WebRequest.Create(string.Format(url, pp.Date.ToString(DateFormat)));
            var res = (HttpWebResponse)wr.GetResponse();
            var doc = new HtmlAgilityPack.HtmlDocument();
            doc.Load(res.GetResponseStream());

            var nodes = doc.DocumentNode.SelectNodes("//comment()");
            if (nodes != null)
            {
                foreach (HtmlAgilityPack.HtmlNode comment in nodes)
                {
                    if (!comment.InnerText.StartsWith("DOCTYPE"))
                        comment.ParentNode.RemoveChild(comment);
                }
            }

            int cellDelta = 0;
            var tbl = doc.GetElementbyId("table5");
            if (pp.Channel == Channel.Channel10)
            {
                tbl = doc.GetElementbyId("table1");
                cellDelta = 1;
            }

            const int childStart = 9;
            var shows = new List<Show>();
            for (int i = childStart; i < tbl.ChildNodes.Count; i += 2)
            {
                var show = new Show();
                var d = Convert.ToDateTime(Tools.CleanupText(tbl.ChildNodes[i].ChildNodes[1].InnerText));
                show.StartTime = pp.Date.AddHours(d.Hour).AddMinutes(d.Minute);
                if (d.Hour < 6) // data is shown from 6 (AM) till next day 6 (AM) so after midnight we need to increase the date
                    show.StartTime = show.StartTime.AddDays(1);
                try
                {
                    show.StartTime = TimeZoneInfo.ConvertTimeToUtc(show.StartTime, TimeZoneInfo.Local);
                }
                catch (Exception ex) // error on the verge of daylight saving start
                {
                    _logger.WriteEntry(ex.Message, LogType.Error);
                    continue;
                }

                show.Title = Tools.CleanupText(tbl.ChildNodes[i].ChildNodes[3 + cellDelta].InnerText);
                var episodeName = Tools.CleanupText(tbl.ChildNodes[i].ChildNodes[5 + cellDelta].InnerText);
                var episodeNumber = Tools.CleanupText(tbl.ChildNodes[i].ChildNodes[7 + cellDelta].InnerText);
                var genere = Tools.CleanupText(tbl.ChildNodes[i].ChildNodes[9 + cellDelta].InnerText);
                show.Description = string.Empty;
                if (!string.IsNullOrEmpty(episodeName))
                    show.Description += string.Format("שם הפרק : {0}\n", episodeName);
                if (!string.IsNullOrEmpty(episodeNumber))
                {
                    show.Description += string.Format("מספר הפרק : {0}\n", episodeNumber);
                    int num;
                    if (int.TryParse(episodeNumber, out num))
                        show.Episode = num;
                }
                if (!string.IsNullOrEmpty(genere))
                    show.Description += string.Format("סוג תכנית : {0}\n", genere);
                shows.Add(show);
            }

            for (int i = shows.Count - 1; i >= 0; i--)
            {
                var show = shows[i];
                if (show.Description != null)
                    show.Description = show.Description.Trim();
                show.Channel = pp.Channel.ToString();
                if (i == shows.Count - 1)
                    show.EndTime = show.StartTime.AddHours(1);
                else
                    show.EndTime = shows[i + 1].StartTime;
            }

            return shows;
        }
开发者ID:hagaygo,项目名称:XmlTvGenerator,代码行数:81,代码来源:WebSiteGrabber.cs

示例12: Follow

        public override int Follow()
        {
            // 沒有資料就離開
            if (string.IsNullOrEmpty(this.DownHome.Data)) return 0;

            int result = 0;
            //BasicInfo gameInfo = null;
            DateTime gameDate = this.GameDate;
            HtmlAgilityPack.HtmlDocument document = new HtmlAgilityPack.HtmlDocument();
            //string xPath = "/html[1]/body[1]/table[2]/tbody[1]/tr[1]/td[1]/table[1]/tbody[1]/tr[2]/td[2]/table[2]/tbody[1]/tr[2]/td[1]/iframe[1]";
            //2015.05.10  04:47改为直接使用ID查找
            // 載入資料
            document.LoadHtml(this.DownHome.Data);
            // 資料位置
            HtmlAgilityPack.HtmlNode nodeGame = document.GetElementbyId("timebf");//document.DocumentNode.SelectSingleNode(xPath);
            // 判斷資料
            if (nodeGame != null)
            {
                #region 下載比賽資料

                // 取出網址
                string webUrl = nodeGame.GetAttributeValue("src", "");
                // 正確的網址
                webUrl = this.DownHome.Uri.ToString() + webUrl;
                // 下載比賽資料
                if (this.DownHomeData.Count == 0)
                {
                    this.DownHomeData.Add(new BasicDownload(this.Sport, webUrl, Encoding.GetEncoding(936)));
                    this.DownHomeData[0].DownloadString();
                }

                #endregion 下載比賽資料

                #region 下載提示資料

                if (this.DownHomeData.Count == 1)
                {
                    this.DownHomeData.Add(new BasicDownload(this.Sport, string.Format(spboUrl + "/s/i.xml"), Encoding.GetEncoding(936)));
                    this.DownHomeData[1].DownloadString();
                }

                #endregion 下載提示資料

                if (!string.IsNullOrEmpty(this.DownHomeData[0].Data))
                {
                    // 載入資料
                    document.LoadHtml(this.DownHomeData[0].Data);

                    #region 取出日期

                    string date = document.DocumentNode.SelectSingleNode("/html[1]/script[1]").InnerText.Trim();
                    string regstr = @"(?i)(?<=<td.*?.*?>)[^<]+(?=日</td>)"; // 提取td的文字
                    Regex reg = new Regex(regstr, RegexOptions.None);
                    if (reg.Match(date).Success)
                    {
                        string gameDateStr = reg.Match(date).Groups[0].Value.Replace("月", "/");
                        // 轉換日期
                        if (!DateTime.TryParse(DateTime.Now.ToString("yyyy") + "/" + gameDateStr, out gameDate))
                        {
                            gameDate = this.GameDate;
                        }
                        // 日期比今天還大,可能是跨年,扣掉一年
                        if (gameDate.Date > DateTime.Now.Date)
                        {
                            gameDate = gameDate.AddYears(-1);
                        }
                    }

                    #endregion 取出日期

                    #region 處理比賽資料

                    if (this.DownHomeData[0].HasChanged)
                    {
                        this.DownHomeData[0].HasChanged = false;

                        string doc = document.DocumentNode.SelectSingleNode("/html[1]").InnerText.Trim();
                        if (string.IsNullOrWhiteSpace(doc))
                        {
                            return 0;
                        }
                        string[] data = doc.Split(new string[] { "var" }, StringSplitOptions.RemoveEmptyEntries);
                        // 判斷資料
                        if (data.Length > 0)
                        {
                            data[0] = data[0].Replace("bf=\"", "");
                            data[0] = data[0].Replace("\";", "");
                            data[0] = data[0].Trim();
                            data = data[0].Split(new string[] { "!" }, StringSplitOptions.RemoveEmptyEntries);

                            ConcurrentDictionary<string, BasicInfo> dicGame = new ConcurrentDictionary<string, BasicInfo>();
                            // 資料
                            int OrderBy = 1;//按照来源网排序
                            foreach (string d in data)
                            {
                                string[] info = d.Split(new string[] { "," }, StringSplitOptions.None);
                                // 資料錯誤就往下處理
                                if (info.Length < 29 || info[14].Trim() == "") continue;
                                // 排除非足球比賽
                                if (info[0] == "NBA" || info[0] == "WNBA" || info[0] == "NCAA" || info[0] == "EBA" ||
//.........这里部分代码省略.........
开发者ID:chanhan,项目名称:ap_follow,代码行数:101,代码来源:Football.cs


注:本文中的HtmlAgilityPack.HtmlDocument.GetElementbyId方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。