等效WebBrowser.Document.GetElementById(“next”).GetAttribute(“v

本文关键字:GetAttribute next GetElementById WebBrowser 等效 Document | 更新日期: 2023-09-27 17:58:38

我需要制作一个程序,从Web视图中加载的页面中获取div的集合,我有这样做的代码,但在C#.net中,我需要在带有C#的Metro应用程序中这样做。

有人能帮我吗?

这是我在c#.net中的代码:

加载时完成

private void explorador_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        if (this.vbuscar & (this.explorador.ReadyState == WebBrowserReadyState.Complete))
        {
            try
            {
                int num = Convert.ToInt32(this.explorador.Document.GetElementById("next").GetAttribute("value"));
                int num2 = Convert.ToInt32(this.explorador.Document.GetElementById("show").GetAttribute("value"));
                while ((num - num2) >= 0)
                {
                    num = Convert.ToInt32(this.explorador.Document.GetElementById("next").GetAttribute("value"));
                    num2 = Convert.ToInt32(this.explorador.Document.GetElementById("show").GetAttribute("value"));
                    this.explorador.Document.InvokeScript("toggle");
                }
                this.hilo_mp3s = new Thread(new ThreadStart(this.iMostrar_Mp3));
                this.hilo_mp3s.IsBackground = true;
                this.hilo_mp3s.Start();
            }
            catch (Exception)
            {
                MessageBox.Show("A ocurrido un error al intentar navegar en internet...'nLa interaccion de la aplicacion con internet no se ha terminado por compleo", "Error al buscar en internet", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                this.vbuscar = false;
                this.cargando.Detener(100);
            }
        }
    }

La Funcion Mostrar MP3

    private void iMostrar_Mp3()
    {
        this.linternet.Invoke(new MethodInvoker (delegate {
            HtmlElementCollection elementsByTagName = this.explorador.Document.GetElementsByTagName("div");
            this.linternet.EliminarTodos();
            foreach (HtmlElement element in elementsByTagName)
            {
                if (element.Id == "song_html")
                {
                    HtmlElementCollection elements2 = element.GetElementsByTagName("div");
                    string innerText = "";
                    foreach (HtmlElement element2 in elements2)
                    {
                        if (element2.GetAttribute("className") == "left")
                        {
                            innerText = element2.InnerText;
                        }
                        if (element2.Id == "right_song")
                        {
                            HtmlElement element3 = element2.GetElementsByTagName("div")[0];
                            string nombre = element3.InnerText;
                            try
                            {
                                HtmlElement element4 = element2.GetElementsByTagName("div")[2].GetElementsByTagName("div")[1].GetElementsByTagName("a")[0];
                                string album = innerText.Replace(''r', ' ').Replace(''n', '-');
                                Uri uri = new Uri(element4.GetAttribute("href"));
                                FileInfo info = new FileInfo(uri.LocalPath);
                                this.linternet.AgregarItem(-777.0, nombre, element4.GetAttribute("href"), info.Directory.Name, album, "--++", 1, "", Resources.iinternetItem, 300);
                                itemlista itemlista = (itemlista) this.lista.Elementos[this.lista.Elementos.Count];
                                itemlista.Imagen = Resources.iinternetItem;
                                itemlista.Imagenplay = Resources.ilista1;
                            }
                            catch
                            {
                            }
                        }
                    }
                }
            }
            this.vbuscar = false;
            this.cargando.Detener(100);
        }));
    }

我只想知道我是如何在C#Metro应用程序中做到这一点的

等效WebBrowser.Document.GetElementById(“next”).GetAttribute(“v

string[] args = { "document.GetElementsByTagName('div')" }
MywebView.InvokeScript("myinvoke", args);

检查这个。。。。