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')
所有的方法,如find_element_by_name
,find_element_by_xpath
,find_element_by_id
等,现在已弃用。
你应该用find_element(By.
代替。
所以,与其
tab = driver.find_element_by_xpath("/html/body/div[2]/div[3]/div/div/div[2]/app-root/div/app-matches/section")
现在应该是
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')
应该改成
tab1 = tab.find_elements(By.TAG_NAME, 'a')
你需要导入这个:
from selenium.webdriver.common.by import By
同时,你必须改进你的定位器。
像/html/body/div[2]/div[3]/div/div/div[2]/app-root/div/app-matches/section
这样的长绝对xpath和CSS选择器非常容易被破坏,而且不可靠。