Reputation: 468
I am scraping the following; https://www.espn.com/nfl/scoreboard/ and trying to get the times of the games
import requests
from bs4 import BeautifulSoup
r = requests.get("https://www.espn.com/nfl/scoreboard")
soup = BeautifulSoup(r.content, "lxml")
for section in soup.find_all("section", {"class": "Card gameModules"}):
for game in section.find_all("section", {"class": "Scoreboard bg-clr-white flex flex-auto justify-between"}):
print(game.find("div", {"class": "ScoreCell__Time ScoreboardScoreCell__Time h9 clr-gray-03"}).text)
Even though it should return the times of the games, it just returns empty strings. Why is this?
Upvotes: 0
Views: 416
Reputation: 16187
Your html class element selection ScoreCell__Time ScoreboardScoreCell__Time h9 clr-gray-03
is correct but empty that's why you are getting empty ResultSet. Select the right content related to the element, then you will get output:
Example:
import requests
from bs4 import BeautifulSoup
r = requests.get("https://www.espn.com/nfl/scoreboard")
soup = BeautifulSoup(r.content, "lxml")
for section in soup.find_all("section", {"class": "Card gameModules"}):
for game in section.find_all("section", {"class": "Scoreboard bg-clr-white flex flex-auto justify-between"}):
print(game.find("div", {"class": "ScoreCell__TeamName ScoreCell__TeamName--shortDisplayName truncate db"}).text)
Output:
Jaguars
Bills
Saints
Texans
Seahawks
Giants
Bengals
Lions
Falcons
Commanders
Eagles
Raiders
Packers
Broncos
Buccaneers
Chargers
Upvotes: 1