Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

How to Scrape NBA starting lineups and create a Pandas DataFrame?

Asked by Dhananjay Singh Nov 1, 2023 2.1K views 1 answer
Share

About this question

I am having trouble parsing the code for the NBA starting lineups and would love some help if possible.

Here is my code so far:

import requests
from bs4 import BeautifulSoup
soup = BeautifulSoup(requests.get(url).text, "html.parser")
print(lineups)
lineups = soup.find_all(class_='lineup__player')

I am looking for the following data: 

  1. Player
  2. Team
  3. Position

I was hoping to scrape the data and then create a Pandas Dataframe from the output.

Here is an example of my desired output:

   Player        Team   Position
Dennis Schroder    BOS      PG
Robert Langford    BOS      SG
Jayson Tatum       BOS      SF
Jabari Parker      BOS      PF
Grant Williams     BOS      C
    Player        Team    Postion
Kyle Lowry         MIA      PG
Duncan Robinson    MIA      SG
Jimmy Butler       MIA      SF
P.J.Tucker         MIA      PF
Bam Adebayo        MIA      C
...               ...      ...

I was able to find the Player data but was unable to successfully parse it. I can see the Player data located inside 'Title'.

Any tips on how to complete this project will be greatly appreciated. Thank you in advance for any help that you may offer.

I am just looking for the 5 starting players... no need to add the bench players. And not sure if there is some way to add a space in between each team like my output above.

Here is and example of the current output that I would like to pars

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.