Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99409

Web scraping shot range data of NBA players in python

$
0
0

I'd like to export the shooting range data. I just got exposed to python. My code is as follows:

from selenium 
import webdriver 
from bs4 import BeautifulSoup

path_to_chromedriver = "D:\chromedriver_win32\chromedriver"  
browser = webdriver.Chrome(executable_path=path_to_chromedriver)
url='https://stats.nba.com/players/shooting/?Season=2002-03&SeasonType=Regular%20Season&sort=25-29%20ft.%20FGA&dir=1'
browser.get(url)
browser.find_element_by_xpath('/html/body/main/div[2]/div/div[2]/div/div/div[1]/div[2]/div/div/label').click()
browser.find_element_by_xpath('/html/body/main/div[2]/div/div[2]/div/div/nba-stat-table/div[3]').click()
table = browser.find_element_by_class_name('nba-stat-table__overflow')
df=[]  
for line_id, lines in enumerate(table.text.split('\n')):  
    if line_id == 0: 
        column_names = lines.split('')[1:] 
    else:
        DFS.append(lines)

For sure I failed to get my answers. That's the reason I come to this platform to ask for your kind help. What I want to get is the data of total 9 pages (428 rows) of that html.


Viewing all articles
Browse latest Browse all 99409

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>