0

我正在研究情绪分类,并且正在解析本地电影数据库中的数据。问题是它们具有三种分类形式。一个有星星(在......中实现)一个“垃圾”,没有给星星或称之为垃圾,这是它的主要链接:http ://www.csfd.cz/film/7049-playgirls/?all=1您需要检查源代码 - 这是一个示例,您可以查看所有三种用户对电影的评价。

</li>
<li id="comment-8356897">
    <h5 class="author"><a href="/uzivatel/138463-campbell/">Campbell</a></h5>
    <img src="http://img.csfd.cz/assets/images/rating/stars/2.gif" class="rating" width="16" alt="**" />
    <div class="info">
        <a href="/uzivatel/138463-campbell/komentare/">všechny komentáře uživatele</a></div>
    <p class="post">Ale jo:-D Když jsem viděl že tenhle film je na prvním místě mezi největšíma sračkama na CSFD, a tak jsem se zhrozil a abych si utrpení ještě vylepšil, tak jsem si pustil oba dva díly naráz. No hell to celkem bylo ale ne nic extrémní. Viděl jsem větší shity. V tomhle filmu jsem měl děsnej problém fandit někomu fandit protože to moc nejde. Šílenost, Ale ne nejhorší.<span class="date desc">(11.3.2011)</span></p>
</li>
<li id="comment-872277">
    <h5 class="author"><a href="/uzivatel/48974-fleker/">fleker</a></h5>

    <div class="info">
        <a href="/uzivatel/48974-fleker/komentare/">všechny komentáře uživatele</a></div>
    <p class="post">tak na todle rači ani koukat nebudu; hodnocení to má slušný ale nechci riskovat aby mi vyschla mícha<span class="date desc">(29.7.2009)</span></p>
</li>
<li id="comment-327360">
    <h5 class="author"><a href="/uzivatel/41698-ozo/">Ozo</a></h5>
    <strong class="rating">odpad!</strong>
    <div class="info">
        <a href="/uzivatel/41698-ozo/komentare/">všechny komentáře uživatele</a></div>
    <p class="post">Změna názoru - tohle si jednu hvězdičku nezaslouží =(<span class="date desc">(29.7.2007)</span></p>
</li>

非常感谢我的计划是这样做的:

string srxPathOfCategory = "//ul[@class='ui-posts-list']//li//img[@class='rating'] | //ul[@class='ui-posts-list']//li//strong[@class='rating']";
        foreach (var att in doc.DocumentNode.SelectNodes(srxPathOfCategory)) // | .//strong[@class='rating']")){
        {

            if (att.InnerText == "odpad!")  //odpad means rubbish
            {
                b[j] = att.InnerText; //saving "odpad!" for later use

            }
            if (att.Attributes["alt"] != null)

            {
                b[j] = att.Attributes["alt"].Value; //these values are from 1* to 5*****

            }
          if (att.InnerText != "odpad!" && att.Attributes["alt"] == null)//this is where the problems starts
            {
                   b[j] = "without user evaluation";

            }

            j++;
        }

这段代码的问题是如果找不到 att.InnerText == "odpad!" 或 att.Attributes["alt"] != null 它继续到下一篇文章并从那里获取用户评价。但是我想至少将某些内容与省略了评估的帖子相匹配。

4

3 回答 3

1

感谢所有帮助,但问题出在 html 的 xpath 中。

我这样解决了

string srxPathOfCategory = "//ul[@class='ui-posts-list']//li";

        foreach (var att in doc.DocumentNode.SelectNodes(srxPathOfCategory))
        {

            foreach (var child in att.ChildNodes.Skip(3)) // skipping first three nodes //- first one is whitespace - marked as #text child node, then there is h5 and third is //another whitespace marked as #text child node 
            {

                if (child.InnerText == "odpad!")
                {
                    b[j] = child.InnerText;
                    Console.WriteLine(b[j]);
                    Console.ReadKey();
                    break;

                }
                else if (child.Attributes["alt"] != null)
                {
                    b[j] = child.Attributes["alt"].Value;
                    Console.WriteLine(b[j]);
                    Console.ReadKey();
                    break;
                }
                else
                {
                    b[j] = "without user evaluation";
                    Console.WriteLine("hlupost");
                    Console.ReadKey();
                    break;
                }

            }
            j++;
        }
于 2013-02-24T14:15:02.993 回答
0

“欧巴!” 不在属性中,在元素中。

于 2013-02-24T01:53:44.440 回答
0

如果你改变你的if陈述怎么办。如果只有一个是真的,为什么还要有 3 个if陈述?

// Is it "odpad" ?
if (att.InnerText == "odpad!")
{
    b[j] = att.InnerText;

}
// .. If not, is it starred?
else if (att.Attributes["alt"] != null)
{
    b[j] = att.Attributes["alt"].Value;

}
// If none of above, it must be this (default)
else
{
       b[j] = "without user evaluation";

}
于 2013-02-24T10:42:26.123 回答