【问题标题】:scraping with Beautiful Soup: print every other value in list off strings用 Beautifulsoup 抓取:打印字符串列表中的所有其他值
【发布时间】:2020-10-28 05:25:57
【问题描述】:

我正在尝试提高 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-圣安东尼奥', “克莱姆森”, '乔治亚科技', '俄亥俄街', “保龄球馆”, '乔治亚州', '弗吉尼亚', 等等

我需要其他所有球队的排名(LSU 雌鸽克莱姆森等) 谢谢

【问题讨论】:

    标签: python beautifulsoup screen-scraping


    【解决方案1】:

    这应该可以解决问题。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 2014-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多