0
import re
import time
from datetime import datetime
from operator import itemgetter

import openpyxl
import pandas as pd
from bs4 import BeautifulSoup
from selenium import webdriver

driver = webdriver.Chrome()
driver.minimize_window()

url = 'https://www.sbostats.com/partite'

tgame = []

driver.get(url)

tab = driver.find_element_by_xpath("/html/body/div[2]/div[3]/div/div/div[2]/app-root/div/app-matches/section")
tab1 = tab.find_elements_by_tag_name('a')
Prophet
  • 32,350
  • 22
  • 54
  • 79
D M
  • 1

1 Answers1

0

All the methods like find_element_by_name, find_element_by_xpath, find_element_by_id etc. are deprecated now.
You should use find_element(By. instead.
So, instead of

tab = driver.find_element_by_xpath("/html/body/div[2]/div[3]/div/div/div[2]/app-root/div/app-matches/section")

it should be now

tab = driver.find_element(By.XPATH, "/html/body/div[2]/div[3]/div/div/div[2]/app-root/div/app-matches/section")

The same about

tab1 = tab.find_elements_by_tag_name('a')

It should be changed to

tab1 = tab.find_elements(By.TAG_NAME, 'a')

You will need to import this:

from selenium.webdriver.common.by import By

Also, you have to improve your locators.
Long absolute XPaths and CSS Selectors like this /html/body/div[2]/div[3]/div/div/div[2]/app-root/div/app-matches/section are extremely breakable and not reliable.

Prophet
  • 32,350
  • 22
  • 54
  • 79
  • hi, it gives me this error: File "c: \ Users \ luigi \ Downloads \ script_sbs.py", line 20, in tab = driver.find_element (By, XPATH, "/ html / body / div [2] / div [3] / div / div / div [2] / app-root / div / app-matches / section") NameError: name 'By' is not defined I'm sorry but I'm a newbie, I didn't do this code – D M Nov 14 '22 at 09:42
  • Ah, OK. See the updated answer. You will need this import `from selenium.webdriver.common.by import By` – Prophet Nov 14 '22 at 09:48
  • What SyntaxError? please share more details. – Prophet Nov 14 '22 at 10:05
  • Hi, adding what you suggested gives me the error described – D M Nov 17 '22 at 17:03
  • Is there a more direct way to contact you? I've been banging my head for months, I'd be grateful – D M Nov 19 '22 at 04:46
  • There is a chat room on my profile page – Prophet Nov 19 '22 at 15:50