Exemplo n.º 1
0
 public async Task Crawl()
 {
     try
     {
         Rootobject obj = JsonConvert.DeserializeObject <Rootobject>(File.ReadAllText(AppDomain.CurrentDomain.BaseDirectory + "Area.txt"));
         foreach (var item in obj.GetType().GetProperties())
         {
             Area rootArea = new Area()
             {
                 Name = item.Name, Url = string.Empty, ParentId = ""
             };
             object Id = areaRepository.Add(rootArea);
             foreach (var p in ParseTool.TransFerType(item.PropertyType.FullName).GetProperties())
             {
                 var  url   = p.GetValue(item.GetValue(obj)).ToString().Substring(0, p.GetValue(item.GetValue(obj)).ToString().IndexOf("|", StringComparison.Ordinal));
                 Area areaa = new Area()
                 {
                     Name     = p.Name,
                     Url      = "http://" + url + ".58.com/",
                     ParentId = Id.ToString()
                 };
                 areaRepository.Add(areaa);
             }
         }
         Console.WriteLine("区域全部抓取完成");
     }
     catch (Exception e)
     {
         log.Error(e.ToString());
     }
 }