Click here to Skip to main content
15,903,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get 6 numbers in the circles in this php page. http://www.millipiyango.gov.tr/sonuclar/_cs_sayisal.php[^]
But when I try to get nodes li it return null. How can I fix this? My code is here.

C#
void cl_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {
            doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(e.Result);
            HtmlNodeCollection nodes=doc.DocumentNode.SelectNodes("//div[@id='sayisal-numaralar']//li");
            foreach(var item in nodes)
            {
              MessageBox.Show(item.InnerText);
            }
        }
Posted
Updated 24-Oct-15 12:10pm
v4

1 solution

You'll not be able to do this with HtmlAgilityPack, you see if you inspect the e.Result's HTML content you'll notice that it has the following:
HTML
<div class="cekilis" id="sayisal-numaralar">
    <!--
    <ul>
        <li>4</li>
        <li>17</li>
        <li>28</li>
        <li>32</li>
        <li>35</li>
        <li>42</li>
    </ul>
    -->
</div>

In other words at first the sayisal-numaralar div represents only a placeholder where the numbers will be added.
Now the one responsible in adding the numbers is the JavaScript located in the script tag (you can also find the JS code by inspecting the e.Result).
The problem you're faced with is that HtmlAgilityPack does not process or run the JS code, thus you'll have to use some other approach for example you can try using the WebBrowser Control[^].
 
Share this answer
 
Comments
Amt-Coder 25-Oct-15 7:43am    
I did this with WebBrowser before. After that I decided it is not good to use a browser control for code simplicity. In this code child nodes of the div node returns #text,#comment,#text in order. Is there any way to reach the li nodes using these?
Mario Z 25-Oct-15 8:53am    
Unfortunately those nodes are not the ones you're targeting. Those nodes are the ones I wrote above, the nodes that you're looking for do not exist because they are dinamically created with JS.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900