<p>您正在查找的定位器是</p>
<pre><code>//div[contains(@class,'event__participant home')][text()='Manchester Utd']//following-sibling::span[1]
^ find a DIV that contains the class indicating a home game
^ that also contains the team name
^ then find the first sibling SPAN that follows
</code></pre>
<p>该定位器将仅为家庭游戏查找包含L、W、D等的元素</p>
<p>如果要等待元素,则需要等待<em>可见</em>,而不是<em>存在</em>。存在是指元素仅在DOM中,但不一定可见。如果要从页面上删除文本,则需要等待可见。您可以使用<code>EC.visibility_of_all_elements_located()</code>来实现这一点。见<a href="https://www.selenium.dev/selenium/docs/api/py/webdriver_support/selenium.webdriver.support.expected_conditions.html#selenium.webdriver.support.expected_conditions.visibility_of_all_elements_located" rel="nofollow noreferrer">the docs</a>。如果在页面存在但不可见时尝试刮除页面,则会引发异常</p>
<p>您的更新代码如下</p>
<pre><code>driver = webdriver.Chrome()
url = "https://www.flashscore.com/team/manchester-united/ppjDR086/results/"
driver.get(url)
Team = 'Manchester Utd'
results = WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.XPATH,"//div[contains(@class,'event__participant home')][text()='" + Team + "']//following-sibling::span[1]")))
print(len(results))
</code></pre>