我對網絡抓取非常陌生,並且在從nba.com抓取一些NBA球員數據時遇到了一些麻煩。我首先試圖用bs4來刮頁面,但碰到一個問題,經過一些研究後,我認爲這是由於我閱讀的文章中的「XHR」。我能夠找到json格式數據的網址,但我的python程序似乎陷入了困境,並且從未加載數據。再次,我在網絡抓取方面很新穎,但是我想我會看看我是否在這裏偏離軌道......有什麼建議嗎?謝謝! (下面的代碼)Scrapping json網頁
import requests
import json
url = "http://stats.nba.com/stats/leaguedashplayerstats?College=&Conference=&Country=&DateFrom=&DateTo=&Division=&DraftPick=&DraftYear=&GameScope=&GameSegment=&Height=&LastNGames=0&LeagueID=00&Location=&MeasureType=Base&Month=0&OpponentTeamID=0&Outcome=&PORound=0&PaceAdjust=N&PerMode=PerGame&Period=0&PlayerExperience=&PlayerPosition=&PlusMinus=N&Rank=N&Season=2017-18&SeasonSegment=&SeasonType=Regular+Season&ShotClockRange=&StarterBench=&TeamID=0&VsConference=&VsDivision=&Weight="
resp = requests.get(url=url)
data = json.loads(resp.text)
print(data)
爲什麼不看圖書館來幫忙? https://github.com/seemethere/nba_py或至少看看他們是如何做到的? – corn3lius
還沒有找到,謝謝你看! – johankent30