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')
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.