Home > Mobile >  How to Add to an Index From a Web Scrape
How to Add to an Index From a Web Scrape

Time:10-18

Am I able to run a while loop and add to the index below to gather all odd number indexes on the page?

Basically, I want to skip all the even indexes and print the odd indexes without writing the same line in asterisks below over and over like [1],[3],[5], etc.

Is there a way to write a while loop and add to the index number?

Thanks!!

'''

import bs4
from bs4 import BeautifulSoup
import requests
import lxml



vegas_insider = requests.get('https://www.vegasinsider.com/nfl/matchups/', 'r').text
soup = BeautifulSoup(vegas_insider, 'lxml')

**team =soup.find_all('a', class_ = 'tableText')[1].text**

print(team)

'''

CodePudding user response:

teams = [team.text for team in soup.find_all('a', class_ = 'tableText')[1::2]]

Or to print,

for team in soup.find_all('a', class_ = 'tableText')[1::2]:
    print(team)
  • Related