Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/6.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# 使用Agility Pack WP8解析HTML页面_C#_Html_Parsing_Windows Phone 8 - Fatal编程技术网

C# 使用Agility Pack WP8解析HTML页面

C# 使用Agility Pack WP8解析HTML页面,c#,html,parsing,windows-phone-8,C#,Html,Parsing,Windows Phone 8,我想解析这个文件:只解析重要的部分 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> ... </head> <body onload="Xaprb.

我想解析这个文件:只解析重要的部分

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
...
</head>
<body onload="Xaprb.InputMask.setupElementMasks()">
<div align="center">
        <table> ... </table>
        <table width="900" height="500" border="0" cellpadding="0"
            cellspacing="0" class="content">
        <tr>
    <td width="45">&nbsp;</td>
    <td width="210" valign="top">
    <div class="np_table">
        <div class="np_bl">
            <div class="np_br">
                <div class="np_tl">
                    <div class="np_tr">
                    <span class="name_heading">Hello</span><br />
                    <span class="name_content">**NAME I NEED**</span><br />
                    <br /> <span class="name_heading">Number:</span><br />
                    <span class="name_content">**NUMBER I NEED**</span>
                    </div>
                </div>
            </div>
        </div>
    </div> <br>

    <div class="menu"> ... </div>

    <p>&nbsp;</p>
    </td>
    <td width="600" valign="top">
        <div class="content_table">
        <div class="ct_bl">
            <div class="ct_br">
                <div class="ct_tl">
                    <div class="ct_tr">
                       <span class="heading">...</span>
                       <p><b>**I need this number too: 250**</b> <br />
               <br />
               Here is the datum I want: **17-04-2014**. <br />
               Please do not...</p>
               <p><b>...</b></p>
    <br /><br>
                 </div>
            </div>
        </div>
      </div>
    </div>
    </td>
</body>
</html>

但我不知道我是如何通过HTML敏捷包获得这些信息的。有人能帮我吗?或者给我一些提示?

我们可以使用XPath查询,使用HtmlAgilityPack选择HTML文档的特定部分。因此,请阅读一些XPath教程开始:

MSDN: W2School: 例如,要从本问题中的示例HTML中获取所需的名称:

var name = 
    doc.DocumentNode
       .SelectSingleNode("//span[@class='name_content' and .='Hello']/following-sibling::span[1]");
if(name!= null) Console.WriteLine(name.InnerText);
解释上述示例中使用的XPath:

//跨度

扫描整个文档中的元素。。。 [@class='name\u content'和.='Hello']

类属性值等于name_content,元素值等于Hello, /以下兄弟姐妹::span[1]

然后从当前获取类型为的最接近的后续同级元素。。。
你可能会发现这很有用。[谢谢!这是名称,但是数字项也在一个span元素中,类名为'Name_content',第二个数字是元素dir,类名为'ct_tr',但是我如何读取特定元素var numbertw中的第一个数字和特定元素var date中的日期?修复了我的示例,我指的是na我。一个问题有很多工作要解决。所以我给出了一个示例,您尝试找出可能用于选择其余部分的条件,然后尝试将这些条件转换为XPath查询。无论您遇到什么问题,请打开一个问题,显示您已经尝试和研究了多远。我现在明白了,谢谢您的帮助!我明白了其余的就不要了!:
var name = 
    doc.DocumentNode
       .SelectSingleNode("//span[@class='name_content' and .='Hello']/following-sibling::span[1]");
if(name!= null) Console.WriteLine(name.InnerText);