我需要创建一个程序,从webview中加载的页面中获取div的集合,我有代码是什么,但是在C#.net中,我需要在带有c#的Metro应用程序中执行此操作。 / p>
可以帮助我吗?
这是我在c#.net中的代码:
On Load_Complete
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应用程序中这样做的。
答案 0 :(得分:0)
string[] args = { "document.GetElementsByTagName('div')" }
MywebView.InvokeScript("myinvoke", args);
检查一下......