Ajuda ! C# - HTMLAGILITYPACK

Bom dia caros amigos.
Estou precisando de ajuda, ja revirei a web e ainda nao estou conseguindo fazer o seguinte.
Estou usando a biblioteca HtmlAgilityPack para fazer o monitoramento de umka webpage constantemente.

Esse é o codigo webHtml que estou monitorando:
(Eu preciso pegar o value que seria o “123 e salvar em uma variavel”)

Total VDC

Eis aqui meu codigo em C#

public void RequerimentoHtml(string url)
{
HtmlAgilityPack.HtmlWeb htmlWeb = new HtmlAgilityPack.HtmlWeb();
HtmlAgilityPack.HtmlDocument htmlDocument = htmlWeb.Load(url);

        List<string> dados = new List<string>();
       
        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 a list dados apresenta esse valores e não (123) Me ajudem por favor =S
header
server_version
content
details-left
details-right

Grato desde ja.

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

Sim ja tentei .SelectNodes("//input[@id]"))

Os dois exemplos que vc mencionou da o erro NullReferenceException was unhandled

Obrigado.

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

listBox1.Items.Add(no.Attributes[“id”].Value + " - " + no.Attributes[“value”].Value);
Da onde esta vindo esse “Items”?

Obrigado

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);

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.

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?

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.

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: