Unain

Wowhead Top10 Search Scrape

May 9th, 2016
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 7.54 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace AeonBot
  8. {
  9.     public class RootObject
  10.     {
  11.         public List<Wowhead> wowhead { get; set; }
  12.         public List<object> hearthstone { get; set; }
  13.     }
  14.  
  15.     public class Lvjson
  16.     {
  17.         // Comments are bugged with arrays
  18.  
  19.         // Standard vars
  20.         public int cat { get; set; }
  21.         //public int chrclass { get; set; }
  22.         public int id { get; set; }
  23.         public int level { get; set; }
  24.         public string name { get; set; }
  25.         /*public int reqclass { get; set; }
  26.         public int schools { get; set; }
  27.         public List<int> talentspec { get; set; }
  28.         public int searchpopularity { get; set; }
  29.         public int? nskillup { get; set; }
  30.         public List<int?> skill { get; set; }
  31.         public string rank { get; set; }*/
  32.  
  33.         // Achievement vars
  34.         public int category { get; set; }
  35.         public string description { get; set; }
  36.         public int parentcat { get; set; }
  37.         public int points { get; set; }
  38.         public int side { get; set; }
  39.         public int type { get; set; }
  40.  
  41.         // NPC vars
  42.         public int classification { get; set; }
  43.         public string tag { get; set; }
  44.  
  45.         // Quest vars
  46.         public int category2 { get; set; }
  47.         public List<List<int>> itemchoices { get; set; }
  48.         public int money { get; set; }
  49.         public int reqlevel { get; set; }
  50.         public int xp { get; set; }
  51.         public List<List<int>> reprewards { get; set; }
  52.  
  53.         // Transmog vars
  54.         public int _note { get; set; }
  55.         public int armorType { get; set; }
  56.         public bool elite { get; set; }
  57.         public bool heroic { get; set; }
  58.         public int maxlevel { get; set; }
  59.         public int minlevel { get; set; }
  60.         public string note { get; set; }
  61.         public List<List<int>> pcbonus { get; set; }
  62.         public List<int> pieces { get; set; }
  63.         public bool raidfinder { get; set; }
  64.         //public int source { get; set; }
  65.  
  66.         // Faction
  67.         public int expansion { get; set; }
  68.  
  69.         // Title
  70.         //public int gender { get; set; }
  71.  
  72.         // Follower
  73.         public List<List<int>> rewards { get; set; }
  74.         public int zone { get; set; }
  75.  
  76.         // Skill
  77.         public int categorybak { get; set; }
  78.         public int profession { get; set; }
  79.         public int recipeSubclass { get; set; }
  80.         public List<int> specializations { get; set; }
  81.         public string icon { get; set; }
  82.  
  83.         // Building
  84.         public string levelname { get; set; }
  85.         public string leveldescription { get; set; }
  86.         public string ingame { get; set; }
  87.         public string texturealliance { get; set; }
  88.         public string texturehorde { get; set; }
  89.         public string buildtime { get; set; }
  90.         public string costcurrency { get; set; }
  91.         public string costamount { get; set; }
  92.         public string costcopper { get; set; }
  93.         public string workorders { get; set; }
  94.         public string followerability { get; set; }
  95.         public string firstseendate { get; set; }
  96.         public string firstseenpatch { get; set; }
  97.         public string firstseenbuild { get; set; }
  98.         public string currencyicon { get; set; }
  99.         public string alliance_file { get; set; }
  100.         public string alliance_x1 { get; set; }
  101.         public string alliance_x2 { get; set; }
  102.         public string alliance_y1 { get; set; }
  103.         public string alliance_y2 { get; set; }
  104.         public string horde_file { get; set; }
  105.         public string horde_x1 { get; set; }
  106.         public string horde_x2 { get; set; }
  107.         public string horde_y1 { get; set; }
  108.         public string horde_y2 { get; set; }
  109.  
  110.         // Hunter Pet
  111.         public int armor { get; set; }
  112.         public int damage { get; set; }
  113.         public int diet { get; set; }
  114.         public int health { get; set; }
  115.  
  116.         // Race
  117.         public int faction { get; set; }
  118.         public int leader { get; set; }
  119.  
  120.         // Zone
  121.         public int territory { get; set; }
  122.  
  123.         // Object
  124.         public List<int> location { get; set; }
  125.  
  126.         // Event
  127.         public List<string> dates { get; set; }
  128.         public int duration0 { get; set; }
  129.         public string endDate { get; set; }
  130.         public int filtertype { get; set; }
  131.         public string startDate { get; set; }
  132.  
  133.         // Class
  134.         public int hero { get; set; }
  135.         public int power { get; set; }
  136.         public int races { get; set; }
  137.         public int roles { get; set; }
  138.         public int weapon { get; set; }
  139.     }
  140.  
  141.     public class Wowhead
  142.     {
  143.         public int type { get; set; }
  144.         public int typeId { get; set; }
  145.         public Lvjson lvjson { get; set; }
  146.     }
  147.  
  148.     // Spell = 6
  149.     // Item = 3
  150.     // Itemset = 4
  151.     // Achievement = 10
  152.     // Npc = 1
  153.     // Title = 11
  154.     // Follower = 21
  155.     // Skill = 15
  156.     // Quest = 5
  157.     // Pet = 9
  158.     // Race = 14
  159.     // (Legion) Champion = ???
  160.     // Currency = 17
  161.     // Faction = 8
  162.     // Building = 20
  163.     // Zone = 7
  164.     // Object = 2
  165.     // Event = 12
  166.     // Sound = ???
  167.     // Class = 13
  168.     // Resource = 27
  169.     // (dont include) Transmog-set = 101
  170.     public enum Categories
  171.     {
  172.         NPC = 1,
  173.         Object,
  174.         Item,
  175.         Itemset,
  176.         Quest,
  177.         Spell,
  178.         Zone,
  179.         Faction,
  180.         Pet,
  181.         Achievement,
  182.         Title,
  183.         Event,
  184.         Class,
  185.         Race,
  186.         Skill,
  187.         Currency = 17,
  188.         Building = 20,
  189.         Follower,
  190.         Resource = 27,
  191.         Transmogset = 101
  192.     }
  193.  
  194.     public class WowheadSite
  195.     {
  196.         private string wowheadsite = "http://www.wowhead.com";
  197.         private string wowheadlegionsite = "http://legion.wowhead.com";
  198.        
  199.         public RootObject Search(string query, bool legion)
  200.         {
  201.             string wowheadSearch = "";
  202.             if (legion)
  203.                 wowheadSearch = wowheadlegionsite + "/search?q=";
  204.             else
  205.                 wowheadSearch = wowheadsite + "/search?q=";
  206.  
  207.             JSONHelper json = new JSONHelper();
  208.             string page = json.GetWebsite(wowheadSearch + "" + query);
  209.  
  210.             if (String.IsNullOrEmpty(page))
  211.                 return null;
  212.  
  213.             string jsonstring = GetJsonString(page);
  214.  
  215.             if (String.IsNullOrEmpty(jsonstring))
  216.                 return null;
  217.  
  218.             return json.Parse(jsonstring);
  219.         }
  220.  
  221.         // Example:
  222.         // { 'type': 6, 'typeId': 33763, 'lvjson': {"cat":-12,"chrclass":1024,"id":33763,
  223.         // "level":36,"name":"@Lifebloom","reqclass":1024,"schools":8,"talentspec":[105],searchpopularity:500}}
  224.         private string GetJsonString(string page)
  225.         {
  226.             // From:
  227.             // var popTop10 =
  228.             int top10StartIndex = page.IndexOf("var popTop10 = ");
  229.             //Console.WriteLine("Index: " + top10StartIndex);
  230.  
  231.             if (top10StartIndex < 0)
  232.                 return null;
  233.  
  234.             // To:
  235.             // };
  236.             int top10LastIndex = page.IndexOf("};", top10StartIndex);
  237.             //Console.WriteLine("Index: " + top10LastIndex);
  238.  
  239.             if (top10LastIndex < 0)
  240.                 return null;
  241.  
  242.             string jsonstring = page.Substring(top10StartIndex + 15, (top10LastIndex + 2) - (top10StartIndex + 15) - 1);
  243.             //Console.WriteLine("Json: " + jsonstring);
  244.  
  245.             return jsonstring;
  246.         }
  247.     }
  248. }
Advertisement
Add Comment
Please, Sign In to add comment