I'm trying to get data from flashscore.com to a project I'm doing as a part of my self-tought Python study:
import requests
from bs4 import BeautifulSoup
res = requests.get("https://www.flashscore.com/")
soup = BeautifulSoup(res.text, "lxml")
games = soup.find_all("div", {'class':['event__match', 'event__match--scheduled', 'event__match--twoLine']})
print(games)
When I run this, it gets me an empty list []
Why?
CodePudding user response:
When an empty list is returned in find_all()
, that means the elements that you specified could not be found.
Make sure that what you are trying to scrape isn't dynamically added such as an iframe in some cases
CodePudding user response:
You want to scrap Flexbox elements. Additionally, it is added dynamically. That's possible, but in different way, see e.g. Scraping flex-element Selenium Python . Try to use the solution from this example mentioned by @cruisepandey, I quote "The xpath that you are using is absolute xpath ... try to replace that with Relative xpath."