Permalink
Browse files

[FIX]

  • Loading branch information...
1 parent 802765e commit c4436848b37aad5548bad1e329e6325b72beabcb Elad Meidar committed Jul 5, 2014
Showing with 34 additions and 6 deletions.
  1. +34 −6 lib/transfermarkt/league.rb
@@ -61,14 +61,42 @@ def self.fetch_by_league_uri(league_uri, fetch_clubs = false)
end
def self.fetch_league_uris
- root_uri = "/en/ligat-haal/startseite/wettbewerb_ISR1.html"
- req = self.get("/#{root_uri}", headers: {"User-Agent" => UserAgents.rand()})
+ competition_uris = ["/wettbewerbe/europa",
+ "/wettbewerbe/asien",
+ "/wettbewerbe/amerika",
+ "/wettbewerbe/afrika"]
+ all_leagues = []
+ competition_uris.each do |competition_uri|
+ all_leagues << Transfermarkt::League.fetch_competition_leagues(competition_uri)
+ end
+
+ all_leagues.flatten
+ end
+
+ def self.fetch_competition_leagues(competition_uri)
+ puts "Fetching #{competition_uri}"
+ req = self.get(competition_uri, headers: {"User-Agent" => UserAgents.rand()})
+ league_uris = []
if req.code != 200
- nil
+ []
else
- root_html = Nokogiri::HTML(req.parsed_response)
- league_uris = root_html.xpath('//*[@id="yw1"]//table//tr//td[2]//a[1]').collect{|player_html| player_html["href"]}
+ competition_html = Nokogiri::HTML(req.parsed_response)
+ league_uris << competition_html.xpath('//*[@id="yw1"]//table[@class="items"]//tr//td[2]//a').collect {|league| league["href"] }
+
+ next_page_link = competition_html.xpath('//*[@id="yw2"]//li[@class="naechste-seite"]//a')[0]
+ if next_page_link
+ league_uris << Transfermarkt::League.fetch_competition_leagues(next_page_link["href"])
+ else
+ league_uris.flatten
+ end
+
+ league_uris.flatten
end
end
end
-end
+end
+
+
+
+
+

0 comments on commit c443684

Please sign in to comment.