Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/337.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# 获取span标记内容?_C#_Tags_Html Agility Pack_Html - Fatal编程技术网

C# 获取span标记内容?

C# 获取span标记内容?,c#,tags,html-agility-pack,html,C#,Tags,Html Agility Pack,Html,好的,我想从标签中获取绘图摘要,但它似乎并不适用于所有网页 这就是我所拥有的: private ArrayList getSynopsis() { for (int i = 0; i < animeURLList.Count; i++) { var mainURL = "http://www.animenewsnetwork.com"; var theHTML = wc.DownloadString(mainURL + (s

好的,我想从标签中获取绘图摘要,但它似乎并不适用于所有网页

这就是我所拥有的:

private ArrayList getSynopsis()
{
    for (int i = 0; i < animeURLList.Count; i++)
    {

            var mainURL = "http://www.animenewsnetwork.com";
            var theHTML = wc.DownloadString(mainURL + (string) animeURLList[i]);
            MessageBox.Show(theHTML);
            //inner html for the span info
            HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
            doc.LoadHtml(theHTML);
            //var array = doc.DocumentNode.SelectNodes("//div[@id='infotype-12'][@class='encyc-info-type br']);
            //MessageBox.Show("got here" + array.ToString());
            ArrayList synopList = new ArrayList();;

            foreach (HtmlNode node doc.DocumentNode.SelectNodes("//div[@id='infotype-12'][@class='encyc-info-type br']"))
            {
                    synopList.Add(node.GetAttributeValue("span", "null"));
            }

    }
    return null;
}
我试图从以下内容中获取文本:

<div id="infotype-12" class="encyc-info-type br">
<strong>Plot Summary:</strong> 
<span>Tooru takes a test so she can enter the same high school as Run, the girl she     likes. She passes, but when she goes to tell Run, she finds her hugging a girl she's never     seen before.</span>
</div>
span标记中有绘图摘要,这正是我试图获取的内容


我仍然无法理解这一点。

在循环中尝试以下操作:

synopList.Add(node.SelectSingleNode("span").InnerText);
此外,您正在使用的XPath:

"//div[@id='infotype-12'][@class='encyc-info-type br']"
最好是:

"//div[@id='infotype-12' and @class='encyc-info-type br']"

谢谢你的加价。还有你的HAP代码就太好了。所以第一条消息出现了,但之后它只给了我:对象引用未设置为对象的实例。@RyanGlen-嗯,函数中的最后一条语句是return null;。。。应该是return synopList;。我改变了这一点,我得到了这个:,这毫无意义,因为第一个概要出现了,然后错误发生了。@RyanGlen-我明白了。将SelectNodes的结果放入一个变量中并对其进行迭代。按照现在编写代码的方式,它会一次又一次地重新蚀刻节点列表。@RyanGlen-是的,确实如此。您是否在foreach上设置了断点并检查了nodez的值。可能没有选择任何节点。