Reputation: 103
I'm trying to pull 2019 CFB rankings but every other value is the next week's opponent and not the next team in the ranking. Is there a way to remove every other value without having to index the list?
base_site = "http://cbssports.com/college-football/rankings/cbs-sports-ranking/"
response = requests.get(base_site)
response
html = response.content
soup = bs(html, 'html.parser')
# Find all links on the page
links = soup.find_all("span", {"class": 'TeamName'})
links
# Inspecting the text inside the links
[link.text for link in links]
response:
['LSU', 'UT-San Antonio', 'Clemson', 'Georgia Tech', 'Ohio St.', 'Bowling Green', 'Georgia', 'Virginia', etc.
With every other team as the ranking I need (LSU hen Clemson, etc.) Thanks
Upvotes: 0
Views: 36
Reputation: 517
This shoudl do the trick.
names = ['LSU', 'UT-San Antonio', 'Clemson', 'Georgia Tech', 'Ohio St.', 'Bowling Green', 'Georgia', 'Virginia']
names = names[1::2]
The second element is chosen by indexing with 1, and then taken at an interval of 2.
Upvotes: 2