我正在尝试使用selenium为一个网站搜集一些信息,下面是网站的链接http://www.ultimatetennisstatistics.com/playerProfile?playerId=4742 我试图得到的信息是在球员'统计'我的代码现在打开球员的个人资料,然后打开球员的统计页,我正在试图找到一种方法来提取球员的统计页下面的信息是我的代码到目前为止
from bs4 import BeautifulSoup
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.ultimatetennisstatistics.com/playerProfile?playerId=4742")
soup = BeautifulSoup(driver.page_source,"lxml")
try:
dropdown = driver.find_element_by_xpath('//*[@id="playerPills"]/li[9]/a')
dropdown.click()
bm = driver.find_element_by_id('statisticsPill')
bm.click()
for i in soup.select('#statistics table.table tr'):
print(i)
data1 = [x.get_text(strip=True) for x in i.select("th,td")]
print(data1)
except ValueError:
print("error")
我 发球
<th class="pct-data text-right"><i class="fa fa-percent"></i></th>
<th class="raw-data text-right" style="display: none;"><i class="fa fa-hashtag"></i></th>
</tr>
</thead>
<tbody>
<tr>
<td>Ace %</td>
<th class="text-right pct-data">23.4%</th>
<th class="raw-data text-right" style="display: none;">12942 / 55377</th>
</tr>
<tr>
<td>Double Fault %</td>
<th class="text-right pct-data">4.2%</th>
<th class="raw-data text-right" style="display:
问题是这条线的位置-
它应该在你点击“统计”标签之后出现。因为只有表加载和soup才能解析它。你知道吗
最终代码-
要从统计信息页面中提取玩家的信息,可以使用以下解决方案:
代码块:
控制台输出:
相关问题 更多 >
编程相关推荐