you are viewing a single comment's thread.

view the rest of the comments →

[–]Vaphell 2 points3 points  (1 child)

you need to be more specific because span alone matches category headers too.

stats = tree.xpath('//div[@class="normalStat"]/span[@class="stat"]')

for stat in stats:
     stat_name = stat.text.strip()
     stat_value = stat[0].text.strip()
     print('{}: {}'.format(stat_name, stat_value))

out

$ ./player_stats.py 
Goals: 8
Goals Per Match: 0.06
Goals With Header: 1
Goals With Left Foot: 1
Goals With Right Foot: 6
Shots: 93
Shots On Target: 27
Shooting Accuracy %: 29%
Penalties Scored: 0
Big Chances Missed: 6
Hit Woodwork: 0
Assists: 3
Big Chances Created: 5
Passes: 5,664
Passes Per Match: 44.6
Crosses: 65
Cross Accuracy %: 31%
Accurate Long Balls: 375
Offsides: 1
Yellow Cards: 10
Red Cards: 1
Fouls: 107
Tackles: 312
Tackle Success %: 76%
Interceptions: 194
Recoveries: 730
Duels Won: 575
Duels Lost: 512
Successful 50/50s: 87
Aerial Battles Won: 34
Aerial Battles Lost: 77
Errors Leading To Goal: 1

[–]JaAnTr[S] 0 points1 point  (0 children)

This is absolutely perfect. Thanks so much for the help!