xpath字符串,用于选择具有特定属性的特定节点

时间:2013-06-15 19:17:05

标签: xpath

我有以下HTML:

<div class=""postrow first"">
                <h2 class=""title icon"">
                    This is the title
                </h2>
                <div class=""content"">
                    <div id=""post_message_1668079"">
                        <blockquote class=""postcontent restore "">
                        <div>Category</div>
                            line 1<br /> line2
                        </blockquote>
                    </div>
                </div>
            </div>
            <div class=""postrow"">
                <h2 class=""title icon"">
                    second title
                </h2>
                <div class=""content"">
                    <div id=""post_message_1668079"">
                        <blockquote class=""postcontent restore "">
                        <div>Category</div>
                            line 1<br /> line2
                        </blockquote>
                    </div>
                </div>
            </div>

xpath 字符串是什么选择属性为“postrow”或“postrow”的所有DIV

1 个答案:

答案 0 :(得分:2)

此答案假定每个"",您的文档中实际上都有"

您可以使用许多替代XPath。这里只有两个:

  • 使用条件|

    //div[@class = "postrow"] | //div[@class = "postrow "]

  • 使用starts-with

    //div[starts-with(@class, "postrow")]