如果一个HTML标签匹配,那么另一个标签应该使用htmlagilitypack抓取

本文关键字:标签 另一个 抓取 htmlagilitypack 一个 如果 HTML | 更新日期: 2023-09-27 18:15:34

<a class="product-name" href="http:xyz" title="Polac pineapple slices 3kg">Polac pineapple slices 3kg</a> <div class="price-box"> <span class="regular-price" id="product-price-5489"> <span class="price">Rs 665</span> </span>

我想从Span标签中获得价格,但它应该在匹配时提供特定项目的价格。比如,如果一个标签的内部文本是Polac pineapple,那么它应该返回665卢比下面是我使用的代码

 ` 
var aTags = document.DocumentNode.SelectNodes("//a");
                var nextTags  = document.DocumentNode.SelectNodes("//span");
if (aTags != null)
                {
                    foreach (var aTag in aTags)
                    {
                        s += counter + ".  " + aTag.InnerText + "<br>";
                        //s += aTag.InnerText;
                        if (aTag.InnerText == "Polac pineapple")
                        {
                            brandcheck = true;
                            find += aTag.InnerText + " ";
                            foreach (var nextTag in nextTags)
                            {
                                //s += counter + ".  " + nextTag.InnerText + "<br>";
                                s += nextTag.InnerText;
                                if (nextTag.InnerText.Contains("Rs"))
                                {
                                    brandcheck = true;
                                    find = nextTag.InnerText + " ";
                                }
                            }`

如果一个HTML标签匹配,那么另一个标签应该使用htmlagilitypack抓取

你能说得更精确点吗?

你可以用"id"

<span id="thisspan">A uniquely identifiable element.</span>

id属性为文档中的元素提供唯一标识符。元素可以使用它来创建指向该特定元素的超链接。

id属性最重要的一点是它必须绝对唯一。class属性可以将相同的值应用于页面中的多个元素,与之不同的是,应用于一个元素的id不能与同一页面中其他地方使用的id匹配。

id属性值必须以罗马字母(a - z或a - z)开头;可以后跟字母(a-z或a-z)、数字(0-9)、连字符(-)、下划线(_)、冒号(:)和点号(.)的任意组合。id值是区分大小写的,因此This is me和This is me将被认为是同一网页上独立且唯一可识别的元素。