mirror of
https://github.com/nprasad2077/nbaStats.git
synced 2026-11-16 06:43:47 +00:00
shot chart scraper prints to console
This commit is contained in:
1 parent
65e434fa64
commit
42528fb917
4 files changed
+3761
-1
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import requests
|
||||
from bs4 import BeautifulSoup, Comment
|
||||
|
||||
url = 'https://www.basketball-reference.com/players/j/jamesle01/shooting/2016'
|
||||
|
||||
response = requests.get(url)
|
||||
soup = BeautifulSoup(response.text, "html.parser")
|
||||
|
||||
# Find the comment containing the shot chart
|
||||
comment = soup.find(string=lambda text: isinstance(text, Comment) and "div_shot-chart" in text)
|
||||
|
||||
if comment: # Make sure we've found the comment before we try to parse it
|
||||
shot_chart_soup = BeautifulSoup(comment, "html.parser")
|
||||
|
||||
# Now you can find the shot chart in the parsed comment
|
||||
shot_chart = shot_chart_soup.find("div", {"id": "div_shot-chart"})
|
||||
|
||||
if shot_chart: # Check that we've found the shot chart
|
||||
shots = shot_chart.find_all("div")
|
||||
|
||||
for shot in shots:
|
||||
print(shot)
|
||||
|
||||
else:
|
||||
print('Shot chart not found')
|
||||
else:
|
||||
print('Comment not found')
|
||||
Reference in new issue
Block a user