Python3 爬取 NBA 2013-2014 赛季比赛数据
生活随笔
收集整理的這篇文章主要介紹了
Python3 爬取 NBA 2013-2014 赛季比赛数据
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
估計大部分都是在預(yù)測獲勝球隊用到這個數(shù)據(jù)吧,網(wǎng)站改版只能按照月份匯總。
大家感興趣可以看爬取代碼,無感直接下載數(shù)據(jù)就好了
import requests from bs4 import BeautifulSoup n1=0 date={} visitor={} home={} v_pts={} h_pts={}def get_detail(url):months=['october','november','december','january','february','march','april','may','june'] for each in range(9):url='https://www.basketball-reference.com/leagues/NBA_2014_games-%s.html'%(months[each])date,visitor,v_pts,home,h_pts,n1=get_detail(url)a=requests.get(url).text soup=BeautifulSoup(a,'lxml') date_game=soup.select('th[scope="row"]') visitor_team_name=soup.select('td[data-stat="visitor_team_name"]') visitor_pts=soup.select('td[data-stat="visitor_pts"]') home_team_name=soup.select('td[data-stat="home_team_name"]')home_pts=soup.select('td[data-stat="home_pts"]') n=len(date_game) global n1 for i in range(n): date[i+n1]=date_game[i].get_text() visitor[i+n1]=visitor_team_name[i].get_text() v_pts[i+n1]=visitor_pts[i].get_text() home[i+n1]=home_team_name[i].get_text() h_pts[i+n1]=home_pts[i].get_text()n1+=n return date,visitor,v_pts,home,h_pts,n1 months=['october','november','december','january','february','march','april','may','june'] for each in range(9):url='https://www.basketball-reference.com/leagues/NBA_2014_games-%s.html'%(months[each])date,visitor,v_pts,home,h_pts,n1=get_detail(url) value={'date':date,'visitor':visitor,'v_pts':v_pts,'home':home,'h_pts':h_pts} import pandas as pd? from pandas import DataFrame,Series dataset=DataFrame(value)
總結(jié)
以上是生活随笔為你收集整理的Python3 爬取 NBA 2013-2014 赛季比赛数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 西安航天的计算机学校,西安航天中学
- 下一篇: html如何绘制热图,推荐一个简单高效的