用 Beautifulsoup 抓取:打印字符串列表中的每个其他值

scraping with Beautiful Soup: print every other value in list off strings

我正在尝试拉出 2019 CFB 排名,但其他所有值都是下周的对手,而不是排名中的下一支球队。有没有办法在不必索引列表的情况下删除所有其他值?

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]

回复:

['LSU', 'UT-San Antonio', 'Clemson', 'Georgia Tech', 'Ohio St.', 'Bowling Green', 'Georgia', 'Virginia', 等等

以我需要的排名(路易斯安那州立大学母鸡克莱姆森等) 谢谢

这应该可以解决问题。

names = ['LSU', 'UT-San Antonio', 'Clemson', 'Georgia Tech', 'Ohio St.', 'Bowling Green', 'Georgia', 'Virginia']

names = names[1::2]

以1为索引选择第二个元素,然后以2为间隔取。