擅长:python、mysql、java
<p>问题是这条线的位置-</p>
<pre><code>soup = BeautifulSoup(driver.page_source,"lxml")
</code></pre>
<p>它应该在你点击“统计”标签之后出现。因为只有表加载和soup才能解析它。你知道吗</p>
<p>最终代码-</p>
<pre><code>from selenium import webdriver
from bs4 import BeautifulSoup
import time
driver = webdriver.Chrome(executable_path=r'//path/chromedriver.exe')
driver.get("http://www.ultimatetennisstatistics.com/playerProfile?playerId=4742")
try:
dropdown = driver.find_element_by_xpath('//*[@id="playerPills"]/li[9]/a')
dropdown.click()
bm = driver.find_element_by_id('statisticsPill')
bm.click()
driver.maximize_window()
soup = BeautifulSoup(driver.page_source,"lxml")
for i in soup.select('#statisticsOverview table tr'):
print(i.text)
data1 = [x.get_text(strip=True) for x in i.select("th,td")]
print(data1)
except ValueError:
print("error")
</code></pre>