John Popa
John Popa

Reputation: 23

Scrape information from FlashScore.ro live

I am trying to scrape information from this website https://www.flashscore.ro/baschet/ from the live tab. I want to receive an email every time something happens.

but my problem is with scraping the code I have until now returns None . I want for now to get the name of the home team.

I am kinda new to this scraping with python thing

import requests 
from bs4 import BeautifulSoup
    
URL = 'https://www.flashscore.ro/baschet/'    
headers = {'user-agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36'}


def find_price():    
    page = requests.get(URL, headers = headers)    
    soup = BeautifulSoup(page.content, 'html.parser')    

    home_team = soup.html.find('div', {'class': 'event__participant event__participant--home'})
    return home_team    

print(find_price())

Upvotes: 0

Views: 1490

Answers (1)

MendelG
MendelG

Reputation: 20088

The website uses JavaScript, but requests doesn't support it. so we can use Selenium as an alternative to scrape the page.

Install it with: pip install selenium.

Download the correct ChromeDriver from here.

from selenium import webdriver
from bs4 import BeautifulSoup
from time import sleep

URL = "https://www.flashscore.ro/baschet/"

driver = webdriver.Chrome(r"C:\path\to\chromedriver.exe")
driver.get(URL)
# Wait for page to fully render
sleep(5)

soup = BeautifulSoup(driver.page_source, "html.parser")

for tag in soup.find_all(
    "div", {"class": "event__participant event__participant--home"}
):
    print(tag.text)


driver.quit()

Output:

Lyon-Villeurbanne
Fortitudo Bologna
Virtus Roma
Treviso
Trieste
Trento
Unicaja
Gran Canaria
Galatasaray
Horizont Minsk 2 F
...And on

Upvotes: 1

Related Questions