Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取表中的文本_C#_Asp.net_Html Parsing_Html Agility Pack - Fatal编程技术网

C# 获取表中的文本

C# 获取表中的文本,c#,asp.net,html-parsing,html-agility-pack,C#,Asp.net,Html Parsing,Html Agility Pack,我有一张这样的桌子。我想从td标签间得到FOO公司的短信。我怎样才能得到它 <table class="left_company"> <tr> <td style="BORDER-RIGHT: medium none; bordercolor="#FF0000" align="left" width="291" bgcolor="#FF0000"> <table cellspacing="0" cellpa

我有一张这样的桌子。我想从td标签间得到FOO公司的短信。我怎样才能得到它

<table class="left_company">
    <tr>
        <td style="BORDER-RIGHT: medium none; bordercolor="#FF0000" align="left" width="291" bgcolor="#FF0000">
            <table cellspacing="0" cellpadding="0" width="103%" border="0">
                <tr style="CURSOR: hand" onclick="window.open('http://www.foo.com')">
                    <td class="title_post" title="FOO" valign="center" align="left" colspan="2">
                        <font style="font-weight: 700" face="Tahoma" color="#FFFFFF" size="2">***FOO COMPANY***</font>
                    </td>
                </tr>
            </table>
        </td>
    </tr>
<table>

您正在调用的页面可能会使用JavaScript生成感兴趣的内容。HtmlAgilityPack不执行JavaScript,因此无法提取内容。确认这一点的一种方法是尝试在关闭脚本的情况下访问页面,并尝试查看您感兴趣的元素是否仍然存在。

关闭:
nS=doc.DocumentNode.SelectNodes(//td[@class='title\u post']//text()”


然后可以打开nS节点来检索文本。如果有多个文本节点,则需要对它们进行迭代。

在字体元素中插入一些属性,如company=“FOO”

然后使用jquery获取该元素,如

alert($('font[company="FOO"]').html())

干杯


Javascript只是打开一个页面。我不认为这是关于js的。
alert($('font[company="FOO"]').html())
var text = doc.DocumentNode.Descendants()
                .FirstOrDefault(n => n.Attributes["class"] != null && 
                                n.Attributes["class"].Value == "title_post")
                .Element("font").InnerText;
var text2 = doc.DocumentNode.SelectNodes("//td[@class='title_post']/font")
               .First().InnerText;