How do you pull data several lines below text you are able to find? That's the short question. More context is below...
I'm learning Python and, as an exercise, I pulled baseball stats from Yahoo Fantasy Baseball to play around with. I coped and pasted the data from the webpage into a text file. It's messy and looks something like this:
Player Note
Charlie Blackmon Col - OF
8:40 pm vs Atl ?
?
Atl
Video Playlist
Video Forecast
Autodraft Hero
115
12
3
99%
159/474
106
27
74
11
.335
?
I was able to set up a simple script to pull out the line with the ballplayers name. See below.
a=open('batters.txt')
for line in a:
if '-' in line:
print(line)
However, I'd also like to pull home run totals (ex. 27) and batting average (ex. .335) from the data.
I'd like it to look something like this:
Charlie Blackmon Col - OF, HR: 27, BA: .335
Thanks in advance for your suggestions!