Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.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# 如果一个html标记匹配,则应使用HtmlAlityPack对另一个标记进行爬网_C#_Html_Web Crawler_Html Agility Pack_Atag - Fatal编程技术网

C# 如果一个html标记匹配,则应使用HtmlAlityPack对另一个标记进行爬网

C# 如果一个html标记匹配,则应使用HtmlAlityPack对另一个标记进行爬网,c#,html,web-crawler,html-agility-pack,atag,C#,Html,Web Crawler,Html Agility Pack,Atag,Rs 665 我想从Span标签中获取价格,但它应该在匹配时提供特定项目的价格。比如,如果标签的内部文本是Polac菠萝,那么它应该返回Rs 665 下面是我正在使用的代码 ` var aTags = document.DocumentNode.SelectNodes("//a"); var nextTags = document.DocumentNode.SelectNodes("//span"); if (aTags != null)


Rs 665

我想从Span标签中获取价格,但它应该在匹配时提供特定项目的价格。比如,如果标签的内部文本是Polac菠萝,那么它应该返回Rs 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 + " ";
                                }
                            }`
`
var aTags=document.DocumentNode.SelectNodes(“//a”);
var nextTags=document.DocumentNode.SelectNodes(“//span”);
如果(aTags!=null)
{
foreach(变量aTag在aTags中)
{
s+=计数器+“+aTag.InnerText+”
”; //s+=aTag.InnerText; 如果(aTag.InnerText==“Polac菠萝”) { brandcheck=true; find+=aTag.InnerText+“”; foreach(nextTags中的变量nextTag) { //s+=计数器+“+nextTag.InnerText+”
”; s+=nextTag.InnerText; if(nextTag.InnerText.Contains(“Rs”)) { brandcheck=true; find=nextTag.InnerText+“”; } }`
你能更精确一点吗

您可以使用“id”

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

id属性最重要的方面是它必须是绝对唯一的。与class属性不同,class属性可能会将相同的值应用于页面中的许多元素,而应用于元素的id不得与同一页面上其他任何位置使用的id匹配


id属性值必须以罗马字母(a–z或a–z)开头;后面可以是字母(a–z或a–z)、数字(0–9)、连字符(-)、下划线(u)、冒号(:)和句点(.)。id值区分大小写,因此“这是我”和“这是我”将被视为同一网页上独立且唯一可识别的元素。

感谢您的回复。实际上,有多个span具有相同id:/like
<span id="thisspan">A uniquely identifiable element.</span>