HTmlAgilityPack尝试获取< li>的问题标签 [英] Problem with HTmlAgilityPack trying to get <li> tags

查看:99
本文介绍了HTmlAgilityPack尝试获取< li>的问题标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在这个php页面的圈子中获得6个数字。 http://www.millipiyango.gov.tr/sonuclar/_cs_sayisal.php [ ^ ]

但是当我尝试获取节点,它返回null。我怎样才能解决这个问题?我的代码就在这里。



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.

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

推荐答案

你将无法用HtmlAgilityPack做到这一点,你看看你是否检查 e.Result 的HTML内容,你会注意到它有以下内容:

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:
<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>



换句话说首先, sayisal-numaralar div仅代表一个占位符,其中将添加数字。

现在负责添加数字的是位于<$ c的JavaScript $ c> script 标签(你也可以通过检查 e.Result 来找到JS代码。)

您遇到的问题是HtmlAgilityPack不处理或运行JS代码,因此您必须使用其他方法,例如您可以尝试使用 WebBrowser控件 [ ^ ]。


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[^].


这篇关于HTmlAgilityPack尝试获取&lt; li&gt;的问题标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆