Strong element returning empty - Htmlagilitypack

1

I'm trying to get content from a strong text from the underwater site. When I open the site with browser I can see in the code the content however, using HtmlAgilityPack the content returns empty.

Example:

    HtmlNodeCollection produtos = document.DocumentNode.SelectNodes("//article[@data-component='single-product']");
    foreach (HtmlNode produto in produtos)
    {
        produto.SelectSingleNode(".//span[@class='sale price']/strong").InnerText.Trim();
    }

Page request

HtmlWeb WebGet = new HtmlWeb ();
HtmlDocument page = webGet.Load("http://busca.submarino.com.br/busca.php?q=eletrodomesticos+e+eletroportateis&page=1")

I need to send POST, add parameters in load or another method to get the content?

    
asked by anonymous 24.11.2014 / 13:49

1 answer

1
private void button1_Click(object sender, EventArgs e)
    {
        var uri = "http://busca.submarino.com.br/busca.php?q=eletrodomesticos+e+eletroportateis&page=1";
        webBrowserControl = new WebBrowser { ScriptErrorsSuppressed = true};

        //exemplo2
        webBrowserControl.ScriptErrorsSuppressed = true;
        webBrowserControl.Navigate(uri);

        waitTillLoad(this.webBrowserControl);

        var doc = new HtmlAgilityPack.HtmlDocument();
        var documentAsIHtmlDocument3 = (mshtml.IHTMLDocument3)webBrowserControl.Document.DomDocument;
        StringReader sr = new StringReader(documentAsIHtmlDocument3.documentElement.outerHTML);
        doc.Load(sr);

        HtmlNodeCollection produtos = doc.DocumentNode.SelectNodes("//article[@data-component='single-product']");
        foreach (HtmlNode produto in produtos)
        {
            Debug.WriteLine("Preço: " + produto.SelectSingleNode(".//span[@class='sale price']/strong").InnerText.Trim());
        }
        Debug.Print("");
    }


    private void waitTillLoad(WebBrowser webBrControl)
    {
        WebBrowserReadyState loadStatus;
        int waittime = 100000;
        int counter = 0;
        while (true)
        {
            loadStatus = webBrControl.ReadyState;
            Application.DoEvents();
            if ((counter > waittime) || (loadStatus == WebBrowserReadyState.Uninitialized) || (loadStatus == WebBrowserReadyState.Loading) || (loadStatus == WebBrowserReadyState.Interactive))
            {
                break;
            }
            counter++;
        }

        counter = 0;
        while (true)
        {
            loadStatus = webBrControl.ReadyState;
            Application.DoEvents();
            if (loadStatus == WebBrowserReadyState.Complete && webBrControl.IsBusy != true)
            {
                break;
            }
            counter++;
        }
    }

Return:

Actually with your code the desired field is not returned, however, with the above code it was possible to perform the desired operation.

    
24.11.2014 / 17:39