Alright folks, let me tell you about this little project I tackled today. The title says it all: “phillies vs atlanta braves match player stats”. Basically, I wanted to grab the player stats from a Phillies vs. Braves game. Why? No real reason, just thought it’d be a cool exercise.

First thing I did was hunt around for a decent data source. I wasn’t about to manually type all that stuff in! I ended up finding a sports stats website that had the box scores I needed. I’m not gonna name names, but it wasn’t too hard to find with a little bit of googling.
Okay, so I had my data. Now the fun part: getting it into a usable format. I decided to go with Python for this. It’s my go-to for this kind of stuff. Plus, I figured I could mess around with the data later if I felt like it.
I started by using the requests
library to pull down the HTML from the webpage. That gave me a big, ugly string of code. Time to clean it up!
This is where BeautifulSoup
came in handy. I fed it the HTML and it parsed it into a nice, nested object that I could easily navigate. Seriously, if you’re not using BeautifulSoup
for web scraping, you’re making your life way harder than it needs to be.
Next, I started digging into the HTML structure of the page to find the tables containing the player stats. This took a little bit of trial and error, using Chrome’s developer tools to inspect the elements and figure out the right CSS selectors. It’s always a bit of a hunt, but eventually I found the right ones.

Once I had the tables, I needed to extract the data from them. I looped through each row and cell, grabbing the text and stuffing it into lists. I had to do some cleaning along the way, removing extra spaces and converting strings to numbers where appropriate. Let me tell you, cleaning data is like 80% of the job!
After wrangling the data into lists, I decided to put it into a more structured format. I created a dictionary for each player, with keys like “Name”, “At Bats”, “Hits”, “RBIs”, etc. Then, I added these dictionaries to a list, one for each team. Now we’re talking!
Finally, I wanted to see the fruits of my labor. I used the pandas
library to create a couple of DataFrames, one for each team. This made it super easy to print the stats in a nice, tabular format. Plus, pandas
has a ton of other features for analyzing and manipulating data, which I might play around with later.
And that was it! I had successfully scraped the player stats from the Phillies vs. Braves game and put them into a usable format. It wasn’t the most glamorous project, but it was a good exercise in web scraping and data manipulation. Plus, now I have a bunch of baseball stats to impress my friends with. Or, you know, just stare at on my own.
Things I learned:

requests
andBeautifulSoup
are a web scraping power couple.- Chrome’s developer tools are essential for inspecting web pages and figuring out the HTML structure.
- Data cleaning is tedious but necessary.
pandas
makes working with tabular data a breeze.
Overall, a fun little project! Might try scraping some more stats tomorrow. Who knows, maybe I’ll build my own fantasy baseball league analyzer or something. The possibilities are endless!