Пример #1
0
        public static List <ANSInfo> GetANSListHTML(string htmlText)
        {
            List <ANSInfo> ansList = new List <ANSInfo>();
            var            html    = new HtmlDocument();

            html.LoadHtml(htmlText);

            HtmlNode           countries = html.GetElementbyId("country");
            HtmlNodeCollection rows      = countries.SelectNodes(".//tbody/tr");

            if (rows != null)
            {
                foreach (HtmlNode row in rows)
                {
                    ANSInfo            ANSInfo = new ANSInfo();
                    HtmlNodeCollection columns = row.SelectNodes("td");
                    columns = row.SelectNodes("td");

                    HtmlNode ansNode = columns[0].SelectSingleNode("./a");
                    ANSInfo.ASN = ansNode.InnerText.Trim();

                    ANSInfo.ASN_Name = columns[1].InnerText.Trim();

                    ANSInfo.Adjacencies_v4 = GetIntFromString(columns[2].InnerText);
                    ANSInfo.Routes_v4      = GetIntFromString(columns[3].InnerText);
                    ANSInfo.Adjacencies_v6 = GetIntFromString(columns[4].InnerText);
                    ANSInfo.Routes_v6      = GetIntFromString(columns[5].InnerText);

                    ansList.Add(ANSInfo);
                }
            }
            return(ansList);
        }
Пример #2
0
        public static string JsonASNInfo(string countryCode, ANSInfo ansInfo)
        {
            StringBuilder jInnards = new StringBuilder();
            JsonWriter    jw       = new JsonTextWriter(new StringWriter(jInnards));

            jw.WritePropertyName(ansInfo.ASN);

            jw.WriteStartObject();
            jw.WritePropertyName("Country");
            jw.WriteValue(countryCode);
            jw.WritePropertyName("Name");
            jw.WriteValue(ansInfo.ASN_Name);
            jw.WritePropertyName("Routes v4");
            jw.WriteValue(ansInfo.Routes_v4);
            jw.WritePropertyName("Routes v6");
            jw.WriteValue(ansInfo.Routes_v6);
            jw.WriteEndObject();

            return(jInnards.ToString());
        }