i can’t get the id while we scrape python

First of all, id and list are built-in functions, so don’t use them as variable names.


The website is loaded dynamically so requests doesn’t support it. 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.it/giocatore/djokovic-novak/AZg49Et9/"
driver = webdriver.Chrome(r"C:\path\to\chromedriver.exe")
driver.get(URL)
sleep(5)

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

for tag in soup.find_all("div", id="g_2_ldRHDOEp"):
    print(tag.get_text(separator=" "))

driver.quit()
   

Output:

30.10. 12:05 Djokovic N. (Srb) Sonego L. (Ita) 0 2 2 6 1 6 P

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top