Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/263.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敏捷包xpath IEnumerable_C#_Asp.net Mvc_Xpath_Html Agility Pack - Fatal编程技术网

C# Html敏捷包xpath IEnumerable

C# Html敏捷包xpath IEnumerable,c#,asp.net-mvc,xpath,html-agility-pack,C#,Asp.net Mvc,Xpath,Html Agility Pack,我不能添加html代码,因为它非常大!5卷或更多。请遵循htmlWeb.load中的链接。 我看这段代码已经两个小时了,我不知道哪里出了问题 HtmlWeb htmlWeb = new HtmlWeb {OverrideEncoding = Encoding.Default}; HtmlAgilityPack.HtmlDocument document = htmlWeb.Load("https://www.parimatch.com/en/sport/futbol/germanija-bund

我不能添加html代码,因为它非常大!5卷或更多。请遵循htmlWeb.load中的链接。 我看这段代码已经两个小时了,我不知道哪里出了问题

HtmlWeb htmlWeb = new HtmlWeb {OverrideEncoding = Encoding.Default};
HtmlAgilityPack.HtmlDocument document = htmlWeb.Load("https://www.parimatch.com/en/sport/futbol/germanija-bundesliga");
var matches = document.DocumentNode.SelectNodes("//tr[@class='bk']").
     Select(tr => new FootballMatch()
     {
         Number = string.Join(" ", tr.SelectNodes("./td[1]//text()[normalize-space()]").Select(t =>t.InnerText)),
         Time = string.Join(" ", tr.SelectNodes("./td[2]//text()[normalize-space()]").Select(t => t.InnerText)),
         Teams  = string.Join(" ", tr.SelectNodes("./td[3]//text()[normalize-space()]").Select(t => t.InnerText)),
         Allowance = string.Join(" ", tr.SelectNodes("./td[4]//text()[normalize-space()]").Select(t => t.InnerText)),
         CoefficientAllowance = string.Join(" ", tr.SelectNodes("./td[5]//text()[normalize-space()]").Select(t => t.InnerText)),
         Total = tr.SelectSingleNode("./td[7]//text()[normalize-space()]").InnerText,
         P1 = tr.SelectSingleNode("./td[10]//text()[normalize-space()]").InnerText,
         X = tr.SelectSingleNode("./td[11]//text()[normalize-space()]").InnerText,
         /*P2 = tr.SelectSingleNode("./td[12]//text()[normalize-space()]").InnerText,
         P1X = tr.SelectSingleNode("./td[13]//text()[normalize-space()]").InnerText,
         P1P2 = tr.SelectSingleNode("./td[14]//text()[normalize-space()]").InnerText,
         P2X = tr.SelectSingleNode("./td[15]//text()[normalize-space()]").InnerText*/
     });
P2,P1X,P1P2,P2X始终为空。 有没有可能使代码更整洁


当你点击一个事件时,会出现一个弹出菜单,这个数据也会被读取,但我不需要这个。如何禁用此功能?

这也不是最漂亮的。但它是有效的。对于某些电池,仍然需要做一些工作。因为有些s包含分隔行。希望这能帮助你继续前进

        string xpath = "//tr[@class='bk']";
        HtmlNodeCollection matches = htmlDoc.DocumentNode.SelectNodes(xpath);

        List<List<string>> footballMatches = new List<List<string>>();

        foreach (HtmlNode x in matches)
        {
            List<string> mess = new List<string>();
            HtmlNodeCollection hTC = x.SelectNodes("./td");
            if (hTC.Count > 15)
            {
                for (int i = 0; i < 15; i++)
                {
                    if (i != 5)
                    {
                        mess.Add(hTC[i].InnerText);
                    }
                }
            }
            footballMatches.Add(mess);
        }

这是不可能的!字段是相同的,但有些是读取的,有些不是!你会感到惊讶的!字段完全相同,但11后无法读取!