帮我写一段python爬虫代码,在NBA官网上爬取得分榜前十球员的名单
时间: 2024-05-05 07:17:53 浏览: 78
基于python的NBA球员数据可视化分析
5星 · 资源好评率100%
好的,以下是Python爬虫代码,可以爬取NBA官网得分榜前十球员的名单:
```
import requests
from bs4 import BeautifulSoup
url = 'https://www.nba.com/stats/players/scoring/?sort=PTS&dir=-1'
response = requests.get(url)
soup = BeautifulSoup(response.content, 'html.parser')
table = soup.find('table', {'class': 'table'})
tbody = table.find('tbody')
players = []
for tr in tbody.find_all('tr')[:10]:
player_name = tr.find_all('td')[1].text.strip()
players.append(player_name)
print('得分榜前十球员名单:')
for i, player in enumerate(players):
print(f'{i+1}. {player}')
```
希望能帮到您!
阅读全文