mirror of
https://github.com/nprasad2077/nbaStats.git
synced 2026-11-06 18:10:39 +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,18 @@
|
||||
# Generated by Django 4.2 on 2023-05-10 02:34
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('nba_data', '0014_playershotchartdata'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='playershotchartdata',
|
||||
name='time_remaining',
|
||||
field=models.CharField(default='', max_length=12),
|
||||
),
|
||||
]
|
||||
+1
-1
@@ -216,7 +216,7 @@ class PlayerShotChartData(models.Model):
|
||||
left = models.IntegerField(null=True)
|
||||
date = models.CharField(max_length=255, default='')
|
||||
qtr = models.CharField(max_length=6, default='')
|
||||
time_remaining = models.IntegerField(null=True)
|
||||
time_remaining = models.CharField(max_length=12, default='')
|
||||
result = models.BooleanField(null=True)
|
||||
shot_type = models.CharField(max_length=6, default='')
|
||||
distance_ft = models.IntegerField(null=True)
|
||||
|
||||
@@ -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')
|
||||
+3715
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user