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


C# HtmlDocument.LoadUrl方法代码示例

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


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

示例1: ctlRaagaBrowser_DocumentComplete

        private void ctlRaagaBrowser_DocumentComplete(object sender, AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent e)
        {
            try
            {
                //Either movie/playlist
                if (((e.uRL.ToString().IndexOf("movie") >= 0) && (e.uRL.ToString().IndexOf("movies") == -1) &&
                    (e.uRL.ToString().IndexOf("fastclick") == -1)) ||
                    (e.uRL.ToString().IndexOf("viewPL") >= 0))
                {
                    currentURL = e.uRL.ToString().Trim();

                    //Load CD image for the movie
                    if ((e.uRL.ToString().IndexOf("movie") >= 0) && (e.uRL.ToString().IndexOf("movies") == -1))
                    {
                        //We are at the movie's song-list page , not in movie list page
                        //
                        //Determine the CD image for the movie. CD images used to correspond to
                        //a HTML image element with src value http://images.raaga.com/Catalog/CD/.../*.jpg
                        //
                        //Parse the page for such a image

                        //Get a AgilityPack HTML document
                        HtmlAgilityPack.HtmlDocument agilityDoc = new HtmlAgilityPack.HtmlDocument();

                        //Load the current HTML into it
                        agilityDoc.LoadUrl(e.uRL.ToString());

                        //Get the image src url, stream it to a image
                        try
                        {
                            //Get the image node
                            HtmlAgilityPack.HtmlNode nodeMovie =
                                agilityDoc.DocumentNode.SelectNodes("//img[contains(@src,'http://images.raaga.com/Catalog/CD')]")[0];

                            //Get the image(movie/album pic)
                            picMovie.Image =
                            Image.FromStream(new System.Net.WebClient().OpenRead(nodeMovie.Attributes["src"].Value));

                            //Get the (movie/album) name
                            lblMovieName.Text = nodeMovie.Attributes["alt"].Value;

                        }
                        catch
                        {
                            picMovie.Image.Dispose();
                            picMovie.Image = null;
                            lblMovieName.Text = "";
                        }
                        finally
                        {
                            agilityDoc = null;
                            System.GC.Collect(0);
                        }

                    }

                    IHTMLDocument2 doc = ((IHTMLDocument2)this.ctlRaagaBrowser.Document);
                    if (doc != null)
                    {
                        //
                        //Get the forms : Raaga songs listed in a form named "raaga"
                        IHTMLFormElement2 oSongForm = null;
                        oSongForm = ((IHTMLFormElement2)doc.forms.item("raaga",0));
                        if (oSongForm != null)
                        {
                            //
                            //If the form called "raaga" is present execute following
                            //script
                            doc.parentWindow.execScript(Signatures.SongListJS,"JavaScript");
                            m_SongsNo = doc.title == "" ? 0 : int.Parse(doc.title);
                            lblSongs.Text = "1/" + m_SongsNo.ToString();
                            lblSongs.Refresh();

                            //
                            //Also attach a IDispatch handler to receive
                            //javascript events in a IE-COM way
                            doc.onclick = this;

                            songPage = true;

                        }

                    }
                }

            }
            catch(Exception _e)
            {
                frmException frm = new frmException();
                frm.ExceptionDialogTitle = "Song list setection problem ";
                frm.ErrorMessage = _e.Message;
                frm.StrackTrace = _e.StackTrace;
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    frm.Dispose();
                    frm = null;
                }
            }
        }
开发者ID:dbose,项目名称:raagahacker,代码行数:99,代码来源:frmMain.cs

示例2: mnuAddSelectedSongs_Click

        private void mnuAddSelectedSongs_Click(object sender, EventArgs e)
        {
            string url = "";

            //Make sure we are at the right spot
            if (songPage == true)
            {
                songPage = false;
                try
                {
                    //Each music has a check box and has following  anchor tag
                    //
                    //  <a href="" onClick="setList1(4785);return false;" class="black">Dil Chahta Hai</a>
                    //
                    //This is our clue. We will get SongID and SongName both from this HTML code

                    //Be defensive
                    if (currentURL != string.Empty)
                    {

                        //Get a AgilityPack HTML document
                        HtmlAgilityPack.HtmlDocument agilityDoc = new HtmlAgilityPack.HtmlDocument();

                        //Load the current HTML into it
                        agilityDoc.LoadUrl(currentURL);

                        //Get the node collection
                        HtmlAgilityPack.HtmlNodeCollection songNodes =
                            agilityDoc.DocumentNode.SelectNodes("//a[@href='']");

                        if (songNodes != null)
                        {
                            //Reset current URL
                            url = currentURL;
                            currentURL = string.Empty;

                            if (songs == null)
                            {
                                songs = new NameValueCollection();
                                HtmlAgilityPack.HtmlAttribute attribute;
                                foreach (HtmlAgilityPack.HtmlNode songNode in songNodes)
                                {
                                    attribute = songNode.Attributes["onClick"];
                                    if (attribute != null)
                                    {
                                        if (attribute.Value.Contains("setList1"))
                                        {
                                            songs.Add(attribute.Value.Substring(9, attribute.Value.IndexOf(")") - 9),
                                                      songNode.InnerText.Trim());
                                        }
                                    }
                                }
                            }

                            //
                            //At this point we have captured all the SongIDs and their corresponding names
                            //Now we need to get the selected songs
                            //
                            //Get the IE document object
                            IHTMLDocument2 doc = ((IHTMLDocument2)this.ctlRaagaBrowser.Document);
                            if (doc != null)
                            {

                                doc.parentWindow.execScript(Signatures.getSongList, "JavaScript");
                                string commaSeparatedSongIDs = doc.title.Trim();
                                if ((commaSeparatedSongIDs != null) & (commaSeparatedSongIDs.Length > 0))
                                {
                                    string[] songIDSelected = null;
                                    if (commaSeparatedSongIDs.IndexOf(",") >= 0)
                                    {
                                        //Multiple songs selected
                                        songIDSelected = commaSeparatedSongIDs.Split(",".ToCharArray());
                                    }
                                    else
                                    {
                                        //Only one song selected
                                        songIDSelected = new string[] { commaSeparatedSongIDs };
                                    }

                                    //Create a new collection only for selected songs
                                    NameValueCollection selectedSongs = new NameValueCollection();
                                    foreach (string songID in songIDSelected)
                                    {
                                        //Get the value for this song ID from the all-song collection
                                        selectedSongs.Add(songID, songs[songID]);
                                    }

                                    //Check we have a valid collection or not
                                    if (selectedSongs.Count != 0)
                                    {

                                        Globals.GetInstance().PlaylistManager.AddMovie(
                                            new RaagaHacker.Playlists.Movie(
                                            (lblMovieName.Text == null ? "" : lblMovieName.Text.Trim()),
                                            selectedSongs));

                                    }

                                }
                            }
//.........这里部分代码省略.........
开发者ID:dbose,项目名称:raagahacker,代码行数:101,代码来源:frmMain.cs


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