c# asp.net获取Alexa排名数据

来源:互联网 发布:网络童星传媒公司 编辑:程序博客网 时间:2024/05/21 06:15

using System;

using System.Collections.Generic;

using System.Text;

using System.Xml;

using System.Net;

using System.IO;



namespace BLL

{

   
public class Alexa

    {

       
public static int GetAlexa(string host)

        {

           
string html = Net.GetHtml("http://data.alexa.com/data/?cli=10&dat=snba&ver=7.0&url=" + host);

           
try

            {

                XmlDocument xml
= new XmlDocument();

                xml.LoadXml(html);

                XmlNode node
= xml.SelectSingleNode("/ALEXA/SD/POPULARITY");

               
if (node != null && node.Attributes["TEXT"] != null)

                   
return int.Parse(node.Attributes["TEXT"].Value);

            }

           
catch

            {

               
int a = html.IndexOf("RANK=/"");

               
if (a > 0)

                {

                   
int b = html.IndexOf("/"", a+6);

                   
if (b>0)

                       
return int.Parse(html.Substring(a+6, b-a-6));

                }

            }

           
return 0;

        }

    }

}

原创粉丝点击