How to loop using .split() function on a text file python
Question: I have a html file with different team names written throughout the file. I
just want to grab the team names. The team names always occur after certain
text and end before certain text, so I've split function to find the team
name. I'm a beginner, and I'm sure I'm making this harder than it is. Data is
the file

    
    
    teams = data.split('team-away">')[1].split("</sp")[0]
        for team in teams:
            print team
    

This returns each individual character for the first team that it finds (so
for example, if teams = San Francisco 49ers, it prints "S", then "A", etc.
instead of what I need it to do: Print "San Francisco 49ers" then on the next
line the next team "Carolina Panthers", etc.

Thank you!


Answer: "I'm a beginner, and I'm sure I'm making this harder than it is."

Well, kind of.

    
    
    import re
    teams = re.findall('team-away">(.*)</sp', data)
    

(with credit to Kurtis, for a simpler regular expression than I originally
had)

Though an actual [HTML
parser](http://docs.python.org/2/library/htmlparser.html) would be best
practice.

