@@ -30,23 +30,30 @@ def scrape
3030
3131 # scrapes the profile page for basic account information
3232 def get_profile_data
33- response = Nokogiri :: HTML ( open ( profile_url ) )
33+ response = Faraday . get profile_url
3434
35- @race = response . css ( "#season-snapshot .module-footer a" ) . first ( ) . inner_html ( )
36- @wins = response . css ( "#career-stats h2" ) . inner_html ( )
37- @achievement_points = response . css ( "#profile-header h3" ) . inner_html ( )
35+ if response . success?
36+ html = Nokogiri ::HTML ( response . body )
37+
38+ @race = html . css ( "#season-snapshot .module-footer a" ) . first ( ) . inner_html ( )
39+ @wins = html . css ( "#career-stats h2" ) . inner_html ( )
40+ @achievement_points = html . css ( "#profile-header h3" ) . inner_html ( )
41+ end
3842 end
3943
4044 # scrapes the league list from account's league page and sets an array of URLs
4145 def get_league_list
42- response = Nokogiri ::HTML ( open ( profile_url + "ladder/leagues" ) )
46+ response = Faraday . get profile_url + "ladder/leagues"
47+ if response . success?
48+ html = Nokogiri ::HTML ( response . body )
4349
44- @leagues = response . css ( "a[href*='#current-rank']" ) . map do |league |
45- {
46- name : league . inner_html ( ) . strip ,
47- id : league . attr ( 'href' ) . sub ( '#current-rank' , '' ) ,
48- href : "#{ profile_url } ladder/#{ league . attr ( 'href' ) } "
49- }
50+ @leagues = html . css ( "a[href*='#current-rank']" ) . map do |league |
51+ {
52+ name : league . inner_html ( ) . strip ,
53+ id : league . attr ( 'href' ) . sub ( '#current-rank' , '' ) ,
54+ href : "#{ profile_url } ladder/#{ league . attr ( 'href' ) } "
55+ }
56+ end
5057 end
5158 end
5259
0 commit comments