Skip to content

Commit 11e8647

Browse files
fix: missing composure field edge case
1 parent 47fac5d commit 11e8647

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

fifa-crawler/fifa_parser/spiders/players_stats.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,14 @@ def parse(self, response):
3434
player_url_photo = player.xpath('//div[@class="bp3-card player" ]//img/@data-src').getall()[0]
3535

3636
# Add stats_names and values (Crossing, finishing) + goalkeeper stats_names and values (GK Diving, GK Reflexes)
37-
total_stats_fields = 34;
38-
player_stats = player.xpath('//div[@class="card"]//ul//li/span[2]//text()').re(r'[\w ]+')
37+
player_stats = player.xpath('//div[@class="card"]//ul//li/span[2]//text()').re(r'[a-zA-Z ]+')
38+
player_stats.insert(-3, "Composure")
39+
player_stats = player_stats + player.xpath('//div[@class="card" and h5="Goalkeeping"]//ul//li/text()').getall()
40+
player_stats_values = player.xpath('//div[@class="card" and h5 !="Profile" and h5 != "Traits" and not(img)]/ul//li/span[1]//text()').getall()
41+
# Compensating for the missing "Composure" field
3942
_player_composure_value = player.xpath('//div[@class="card"]//ul//li[text()=" Composure"]/text()').get()
4043
if _player_composure_value != None:
41-
player_stats.insert(-3, _player_composure_value[1:])
42-
else:
43-
player_stats.insert(-3, 50)
44-
total_stats_fields -= 1
45-
player_stats = player_stats + player.xpath('//div[@class="card" and h5="Goalkeeping"]//ul//li/text()').getall()
46-
player_stats_values = player.xpath('//div[@class="card" and h5 !="Profile" and h5 != "Traits"]/ul//li/span[1]//text()').getall()[-total_stats_fields:]
44+
player_stats_values.insert(25, 50)
4745

4846
# Overall rating, potential rating + value, wage names and values
4947
primary_stats = player.xpath('//div[@class="sub"]//text()').getall()

0 commit comments

Comments
 (0)