Reputation: 3
I am using beautifulsoup to scrape some basic data. The parts of the source code I need are:
<div class="header-team">Team name 1</div>
<div class="header-team">Team name 2</div>
The two lines are not next to each other.
I am trying this:
for team in soup.findAll('div', 'header-team')
print team
But get all the code returned. I have tried adding on .text but it returns an error.
Upvotes: 0
Views: 1344
Reputation: 5292
Below code is working to me-
from bs4 import BeautifulSoup as bs
data = """<div class="header-team">Team name 1</div>
<div class="header-team">Team name 2</div>"""
soup = bs(data,'lxml')
for team in soup.findAll('div', 'header-team'):
print team.text
Output-
Team name 1
Team name 2
Upvotes: 1