Skip to content
Advertisement

Trying to get data from a table using beautifulsoup in python

Trying to get the “all splits” line of numbers from https://insider.espn.com/nba/player/splits/_/id/532/type/nba/year/2003/category/perGame (html code is in the picture) my code returns the ‘all splits’ text instead of the numbers I’m looking for. How do I go about changing the lookups in the GetStats function area to get the numbers instead of the first column descriptors.

JavaScript

Advertisement

Answer

To get the all_splits stats from: https://insider.espn.com/nba/player/splits/_/id/532/type/nba/year/2003/category/perGame

This is what I did:

  • I grabbed the table body using soup.select
  • Then I grabbed the headings and relevant stats by iterating through the columns/rows.

The list comprehension provides the text in list format, which is easy to convert to a dataframe.

Code:

JavaScript

Output:

all_splits

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement