negovei 23 de abr. de 2012
Já testou no foreach usar .SelectNodes("//input[@id ]"))
ou ainda ir direto na tag pelo id?
.SelectNodes("//*[@id=“total”]"))
Obs: não tive como testar! (só em casa :p)
flw’s
Leandro_Caputo 23 de abr. de 2012
Sim ja tentei .SelectNodes("//input[@id ]"))
Os dois exemplos que vc mencionou da o erro NullReferenceException was unhandled
Obrigado.
negovei 23 de abr. de 2012
Fiz isso e funcionou:
HtmlAgilityPack .HtmlNode no = htmlDocument .GetElementbyId ( "total" ) ;
if ( no .Attributes ["id" ].Value != null )
listBox1 .Items .Add ( no .Attributes ["id" ].Value + " - " + no .Attributes ["value" ].Value ) ;
Vai debugando e vendo qual conteúdo está no objeto.
flw’s
Leandro_Caputo 23 de abr. de 2012
listBox1.Items.Add(no.Attributes[“id”].Value + " - " + no.Attributes[“value”].Value);
Da onde esta vindo esse “Items”?
Obrigado
Leandro_Caputo 23 de abr. de 2012
Vc tirou toda essa parte do meu codigo
if (dados != null)
{
foreach (HtmlAgilityPack.HtmlNode NODE in htmlDocument.DocumentNode.SelectNodes("//div[@id ]"))
{
dados.Add(NODE.Attributes[“id”].Value);
}
foreach (string str in dados)
{
richTextBox1.Text += str + “\n”;
}
e substitui por isso?
HtmlAgilityPack .HtmlNode no = htmlDocument .GetElementbyId ( “total ”) ;
if ( no .Attributes [“id ”].Value != null )
listBox1 .Items .Add ( no .Attributes [“id ”].Value + " - " + no .Attributes [“value ”].Value ) ;
negovei 23 de abr. de 2012
Então, foi isso mesmo só que usei um listbox no exemplo que fiz aqui. Serve só como base.
Mas você pode varrer o node da mesma forma.
O Items é do listbox.
Leandro_Caputo 23 de abr. de 2012
INTAO NO LUGAR DO LISTA BOX EU UTILIZO UM list TEM DIFERENÇA?
Tipo eu substitui pelo seu evxemplo e da erro no if (no.Attributes[“id”].Value != null)
tem msn?
negovei 23 de abr. de 2012
Também funciona assim:
public void requerimentoHtml ( string url )
{
var htmlWeb = new HtmlAgilityPack . HtmlWeb ();
var htmlDocument = htmlWeb . Load ( url );
var dados = new List < string > ();
foreach ( var node in htmlDocument . DocumentNode . SelectNodes ( "//input[@id]" ))
dados . Add ( node . Attributes [ "value" ] . Value );
foreach ( var str in dados )
richTextBox1 . Text += str + " \n " ;
}
Obs: Não me preocupei em refatorar o código.
Leandro_Caputo 24 de abr. de 2012
Galera muito obrigado pela ajuda de todos, depois de bater muito com a cara no monitor finalmente consegui.
Este é o código
public void RequerimentoHtml(string url)
{
HtmlAgilityPack.HtmlWeb htmlWeb = new HtmlAgilityPack.HtmlWeb();
HtmlAgilityPack.HtmlDocument htmlDocument = htmlWeb.Load(url);
List < string > dados = new List < string > () ;
HtmlAgilityPack .HtmlNode htmlNode = htmlDocument .GetElementbyId ( "total" ) ;
if ( htmlNode .Attributes ["id" ].Value != null )
{
dados .Add ( htmlNode .Attributes ["id" ].Value + " - " + htmlNode .Attributes ["value" ].Value ) ;
}
foreach ( string str in dados )
{
richTextBox1 .Text += str + "\n" ;
}
}
:twisted: