예제 #1
0
        private static Table GetTableFromRowNode(HtmlNode node, bool isOdd, TableCommonData data)
        {
            //deal with the \r\n
            node.InnerHtml = node.InnerHtml.Replace("\r", "").Replace("\n", "").Trim();
            var t         = new Table();
            var firstNode = node.FirstChild;

            //if its a odd no then get the table info
            if (isOdd)
            {
                data.TableUrl = GetFullUrl(firstNode.SelectSingleNode("//a").GetAttributeValue("href", ""));
                data.TableNo  = firstNode.SelectSingleNode("//a").InnerHtml;
                firstNode.Remove();
                //this two f*****g data is columspan=2 f**k!
                data.HomeImp     = node.SelectNodes("td")[12].InnerText.Trim();
                data.VisitingImp = node.SelectNodes("td")[13].InnerText.Trim();
                node.SelectNodes("td")[12].Remove();
                //when removed 12th then the 13th becomes the 12th
                node.SelectNodes("td")[12].Remove();

                //奇数和偶数的人位置不同
                t.NPlayer =
                    node.SelectNodes("td")[0].SelectSingleNode("table")
                    .SelectSingleNode("tr")
                    .SelectSingleNode("td")
                    .NextSibling.InnerText.Trim();
                t.SPlayer = node.SelectNodes("td")[1].SelectSingleNode("table")
                            .SelectSingleNode("tr")
                            .SelectSingleNode("td")
                            .NextSibling.InnerText.Trim();
                t.EPlayer = node.SelectNodes("td")[2].SelectSingleNode("table")
                            .SelectSingleNode("tr")
                            .SelectSingleNode("td")
                            .NextSibling.InnerText.Trim();
                t.WPlayer = node.SelectNodes("td")[3].SelectSingleNode("table")
                            .SelectSingleNode("tr")
                            .SelectSingleNode("td")
                            .NextSibling.InnerText.Trim();
            }
            else
            {
                t.NPlayer =
                    node.SelectNodes("td")[2].SelectSingleNode("table")
                    .SelectSingleNode("tr")
                    .SelectSingleNode("td")
                    .NextSibling.InnerText.Trim();
                t.SPlayer = node.SelectNodes("td")[3].SelectSingleNode("table")
                            .SelectSingleNode("tr")
                            .SelectSingleNode("td")
                            .NextSibling.InnerText.Trim();
                t.EPlayer = node.SelectNodes("td")[0].SelectSingleNode("table")
                            .SelectSingleNode("tr")
                            .SelectSingleNode("td")
                            .NextSibling.InnerText.Trim();
                t.WPlayer = node.SelectNodes("td")[1].SelectSingleNode("table")
                            .SelectSingleNode("tr")
                            .SelectSingleNode("td")
                            .NextSibling.InnerText.Trim();
            }
            t.TableData = data;
            t.OpenOrNot = node.SelectNodes("td")[4].InnerText.Trim();
            t.Decl      = node.SelectNodes("td")[5].InnerText.Trim();
            t.Cont      = node.SelectNodes("td")[6].InnerText.Trim();
            t.Result    = node.SelectNodes("td")[7].InnerText.Trim();
            t.NSPoints  = node.SelectNodes("td")[8].InnerText.Trim();
            t.EWPoints  = node.SelectNodes("td")[9].InnerText.Trim();
            t.Datum     = node.SelectNodes("td")[10].InnerText.Trim();
            t.XImp      = node.SelectNodes("td")[11].InnerText.Trim();
            //主客队名称要到Table的链接中取
            var teamData = GetHtmlDocFromUrl(t.TableData.TableUrl);

            t.HomeTeamName     = teamData.DocumentNode.SelectSingleNode("//span[@id='lHomeTeamName']").InnerText;
            t.VisitingTeamName = teamData.DocumentNode.SelectSingleNode("//span[@id='lVisitTeamName']").InnerText;
            t.HomeRoundImp     = teamData.DocumentNode.SelectSingleNode("//span[@id='lHomeIMPs']").InnerText;
            t.VisitingRoundImp = teamData.DocumentNode.SelectSingleNode("//span[@id='lVisitIMPs']").InnerText;
            return(t);
        }
예제 #2
0
        private BoardInfo LoadBoardResults(string url)
        {
            url = GetFullUrl(url);
            var boardData = GetPageData(url);

            //get data we need
            boardData = boardData.Replace(TopPrefix, "");
            var hDoc = new HtmlAgilityPack.HtmlDocument();

            hDoc.LoadHtml(boardData);
            //valid if someone we need in this page
            //if (!IsTheBoardWeNeed(hDoc))
            //{
            //    return null;
            //}
            var boardNo = hDoc.DocumentNode.SelectNodes("//span[@id='lBoardNo']");
            //N
            var lNs = hDoc.DocumentNode.SelectNodes("//span[@id='lNs']");
            var lNh = hDoc.DocumentNode.SelectNodes("//span[@id='lNh']");
            var lNd = hDoc.DocumentNode.SelectNodes("//span[@id='lNd']");
            var lNc = hDoc.DocumentNode.SelectNodes("//span[@id='lNc']");
            //W
            var lWs = hDoc.DocumentNode.SelectNodes("//span[@id='lWs']");
            var lWh = hDoc.DocumentNode.SelectNodes("//span[@id='lWh']");
            var lWd = hDoc.DocumentNode.SelectNodes("//span[@id='lWd']");
            var lWc = hDoc.DocumentNode.SelectNodes("//span[@id='lWc']");
            //S
            var lSs = hDoc.DocumentNode.SelectNodes("//span[@id='lSs']");
            var lSh = hDoc.DocumentNode.SelectNodes("//span[@id='lSh']");
            var lSd = hDoc.DocumentNode.SelectNodes("//span[@id='lSd']");
            var lSc = hDoc.DocumentNode.SelectNodes("//span[@id='lSc']");
            //E
            var lEs = hDoc.DocumentNode.SelectNodes("//span[@id='lEs']");
            var lEh = hDoc.DocumentNode.SelectNodes("//span[@id='lEh']");
            var lEd = hDoc.DocumentNode.SelectNodes("//span[@id='lEd']");
            var lEc = hDoc.DocumentNode.SelectNodes("//span[@id='lEc']");
            //dlr
            var dlr = hDoc.DocumentNode.SelectNodes("//span[@id='lDealer']");
            //vul
            var vul = hDoc.DocumentNode.SelectNodes("//span[@id='lVulnerable']");
            var bi  = new BoardInfo();

            bi.BoardNumber = int.Parse(boardNo.Single().InnerText);
            bi.Datum       = hDoc.DocumentNode.SelectSingleNode("//span[@id='lDatum']").InnerHtml;

            bi.N.Spades   = lNs.Single().InnerText;
            bi.N.Hearts   = lNh.Single().InnerText;
            bi.N.Diamonds = lNd.Single().InnerText;
            bi.N.Clubs    = lNc.Single().InnerText;
            bi.W.Spades   = lWs.Single().InnerText;
            bi.W.Hearts   = lWh.Single().InnerText;
            bi.W.Diamonds = lWd.Single().InnerText;
            bi.W.Clubs    = lWc.Single().InnerText;
            bi.S.Spades   = lSs.Single().InnerText;
            bi.S.Hearts   = lSh.Single().InnerText;
            bi.S.Diamonds = lSd.Single().InnerText;
            bi.S.Clubs    = lSc.Single().InnerText;
            bi.E.Spades   = lEs.Single().InnerText;
            bi.E.Hearts   = lEh.Single().InnerText;
            bi.E.Diamonds = lEd.Single().InnerText;
            bi.E.Clubs    = lEc.Single().InnerText;
            bi.Dlr        = dlr.Single().InnerText;
            bi.Vul        = vul.Single().InnerText;

            //set poker
            var             rowNodes = hDoc.DocumentNode.SelectNodes("//table[@class='resultTable']/tr");
            TableCommonData data     = new TableCommonData();

            for (int i = 0; i < rowNodes.Count; i++)
            {
                if (i == 0 || !teamMembers.Any(p => rowNodes[i].InnerText.Contains(p)))
                {
                    continue;
                }
                var isOdd = i % 2 == 1;
                if (isOdd)
                {
                    data = new TableCommonData();
                }
                bi.Table.Add(GetTableFromRowNode(rowNodes[i], isOdd, data));
                //get the team result
            }

            //loop the tables and find out guys in our team
            //bi must has two tables?
            if (bi.Table.Count == 2)
            {
                bi.Nplayer = bi.Table.Single(p => teamMembers.Contains(p.NPlayer)).NPlayer;
                bi.Wplayer = bi.Table.Single(p => teamMembers.Contains(p.WPlayer)).WPlayer;
                bi.Eplayer = bi.Table.Single(p => teamMembers.Contains(p.EPlayer)).EPlayer;
                bi.Splayer = bi.Table.Single(p => teamMembers.Contains(p.SPlayer)).SPlayer;
            }

            return(bi);
        }