-2

わかりましたので、タグ内からプロットの概要を取得したいのですが<span>、すべての Web ページで機能するわけではないようです。

これは私が持っているものです:

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 タグには、私が取得しようとしているプロットの要約が含まれています。

私はまだこれを理解することができません。

4

1 に答える 1

0

ループで次のことを試してください。

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']"
于 2012-08-19T17:47:45.763 に答える