|
1 | 1 | # BnetScraper |
2 | 2 |
|
3 | | -A Nokogiri-based scraper of Battle.net profiles. Currently this only includes Starcraft2. |
| 3 | +BnetScraper is a Nokogiri-based scraper of Battle.net profile information. Currently this only includes Starcraft2. |
| 4 | + |
| 5 | +# Installation |
| 6 | + |
| 7 | +Run `gem install bnet_scraper` or add `gem 'bnet_scraper'` to your `Gemfile`. |
4 | 8 |
|
5 | 9 | # Usage |
6 | 10 |
|
7 | | -The gem allows you to parse profiles separate from individual leagues, using `BnetScraper::Starcraft2::ProfileScraper` |
8 | | -or `BnetScraper::Starcraft2::LeagueScraper`. See documentation for more information on those. |
| 11 | +All of the scrapers take an options hash, and can be created by either passing a URL string for the profile URL or |
| 12 | +passing the account information in the options hash. Thus, either of these two approaches work: |
| 13 | + |
| 14 | +``` ruby |
| 15 | +BnetScraper::Starcraft2::ProfileScraper.new(url: 'http://us.battle.net/sc2/en/profile/12345/1/TestAccount/') |
| 16 | +BnetScraper::Starcraft2::ProfileScraper.new(bnet_id: '12345', account: 'TestAccount', region: 'na') |
| 17 | +``` |
| 18 | + |
| 19 | +There are several scrapers that pull various information. They are: |
| 20 | + |
| 21 | +* BnetScraper::Starcraft2::ProfileScraper - collects basic profile information and an array of league URLs |
| 22 | +* BnetScraper::Starcraft2::LeagueScraper - collects data on a particular league for a particular Battle.net account |
| 23 | +* BnetScraper::Starcraft2::AchievementScraper - collects achievement data for the account. |
| 24 | +* BnetScraper::Starcraft2::MatchHistoryScraper - collects the 25 most recent matches played on the account |
| 25 | + |
| 26 | +All scrapers have a `#scrape` method that triggers the scraping and storage. By default they will return the result, |
| 27 | +but an additional `#output` method exists to retrieve the results subsequent times without re-scraping. |
| 28 | + |
| 29 | +## BnetScraper::Starcraft2::ProfileScraper |
| 30 | + |
| 31 | +This pulls basic profile information for an account, as well as an array of league URLs. This is a good starting |
| 32 | +point for league scraping as it provides the league URLs necessary to do supplemental scraping. |
| 33 | + |
| 34 | +``` ruby |
| 35 | +scraper = BnetScraper::Starcraft2::ProfileScraper.new(url: 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/') |
| 36 | +scraper.scrape |
| 37 | +# => { |
| 38 | + bnet_id: '2377239', |
| 39 | + account: 'Demon', |
| 40 | + bnet_index: 1, |
| 41 | + race: 'Protoss', |
| 42 | + wins: '684', |
| 43 | + achievement_points: '3630', |
| 44 | + leagues: [ |
| 45 | + { |
| 46 | + name: "1v1 Platinum Rank 95", |
| 47 | + id: "96905", |
| 48 | + href: "http://us.battle.net/sc2/en/profile/2377239/1/Demon/ladder/96905#current-rank" |
| 49 | + } |
| 50 | + ] |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +## BnetScraper::Starcraft2::LeagueScraper |
| 55 | + |
| 56 | +This pulls information on a specific league for a specific account. It is best used either in conjunction with a |
| 57 | +profile scrape that profiles a URL, or if you happen to know the specific league\_id and can pass it as an option. |
| 58 | + |
| 59 | +``` ruby |
| 60 | +scraper = BnetScraper::Starcraft2::LeagueScraper.new(league_id: '12345', account: 'Demon', bnet_id: '2377239') |
| 61 | +scraper.scrape |
| 62 | +# => { |
| 63 | + season: '6', |
| 64 | + name: 'Aleksander Pepper', |
| 65 | + division: 'Diamond', |
| 66 | + size: '4v4', |
| 67 | + random: false, |
| 68 | + bnet_id: '2377239', |
| 69 | + account: 'Demon' |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +## BnetScraper::Starcraft2::AchievementScraper |
| 74 | + |
| 75 | +This pulls achievement information for an account. Note that currently only returns the overall achievements, |
| 76 | +not the in-depth, by-category achievement information. |
| 77 | + |
| 78 | +``` ruby |
| 79 | +scraper = BnetScraper::Starcraft2::AchievementScraper.new(url: 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/') |
| 80 | +scraper.scrape |
| 81 | +# => { |
| 82 | + recent: [ |
| 83 | + { title: 'Blink of an Eye', description: 'Complete round 24 in "Starcraft Master" without losing any stalkers', earned: '3/5/2012' }, |
| 84 | + { title: 'Whack-a-Roach', description: 'Complete round 9 in "Starcraft Master" in under 45 seconds', earned: '3/5/2012' }, |
| 85 | + { title: 'Safe Zone', description: 'Complete round 8 in "Starcraft Master" without losing any stalkers', earned: '3/5/2012' }, |
| 86 | + { title: 'Starcraft Master', description: 'Complete all 30 rounds in "Starcraft Master"', earned: '3/5/2012' }, |
| 87 | + { title: 'Starcraft Expert', description: 'Complete any 25 rounds in "Starcraft Master"', earned: '3/5/2012' }, |
| 88 | + { title: 'Starcraft Apprentice', description: 'Complete any 20 rounds in "Starcraft Master"', earned: '3/5/2012' } |
| 89 | + ], |
| 90 | + showcase: [ |
| 91 | + { title: 'Hot Shot', description: 'Finish a Qualification Round with an undefeated record.' }, |
| 92 | + { title: 'Starcraft Master', description: 'Complete all rounds in "Starcraft Master"' }, |
| 93 | + { title: 'Team Protoss 500', description: 'Win 500 team league matches as Protoss' }, |
| 94 | + { title: 'Night of the Living III', description: 'Survive 15 Infested Horde Attacks in the "Night 2 Die" mode of the "Left 2 Die" scenario.' }, |
| 95 | + { title: 'Team Top 100 Diamond', description: 'Finish a Season in Team Diamond Division' } |
| 96 | + |
| 97 | + ], |
| 98 | + progress: { |
| 99 | + liberty_campaign: '1580', |
| 100 | + exploration: '480', |
| 101 | + custom_game: '330', |
| 102 | + cooperative: '660', |
| 103 | + quick_match: '170' |
| 104 | + } |
| 105 | +} |
| 106 | +``` |
| 107 | + |
| 108 | +## BnetScraper::Starcraft2::MatchHistoryScraper |
| 109 | + |
| 110 | +This pulls the 25 most recent matches played for an account. Note that this is only as up-to-date as battle.net is, and |
| 111 | +will likely not be as fast as in-game. |
| 112 | + |
| 113 | +``` ruby |
| 114 | +scraper = BnetScraper::Starcraft2::MatchHistoryScraper.new(url: 'http://us.battle.net/sc2/en/profile/2377239/1/Demon/') |
| 115 | +scraper.scrape |
| 116 | +# => { |
| 117 | + wins: '15', |
| 118 | + losses: '10', |
| 119 | + matches: [ |
| 120 | + { map_name: 'Bx Monobattle - Sand Canyon (Fix)', outcome: :win, type: 'Custom', date: '3/12/2012' }, |
| 121 | + { map_name: 'Deadlock Ridge', outcome: :loss, type: '4v4', date: '3/12/2012' }, |
| 122 | + { map_name: 'District 10', outcome: :win, type: '4v4', date: '3/12/2012' }, |
| 123 | + # ... |
| 124 | + ] |
| 125 | +} |
| 126 | +``` |
| 127 | + |
| 128 | +# Contribute! |
| 129 | + |
| 130 | +I would love to see contributions! Please send a pull request with a feature branch containing specs |
| 131 | +(Chances are excellent I will break it if you do not) and I will take a look. Please do not change the version |
| 132 | +as I tend to bundle multiple fixes together before releasing a new version anyway. |
| 133 | + |
| 134 | +# Author |
9 | 135 |
|
10 | | -One convenience function, `BnetScraper::Starcraft2#full_profile_scrape`, exists to do a full scrape of a given profile. |
11 | | -Note that this is a rather slow function given the number of HTTP calls necessary to retrieve all of the data. |
| 136 | +Written by [Andrew Nordman](http://github.com/cadwallion), see LICENSE for details. |
0 commit comments