python - Data scraping basketball data using beautiful soup -


i want return names of these 3 players (in url).. current code returns name, team, , basketball association. there can specify in code return names?

data scraping here:

import requests     bs4 import beautifulsoup   def bball_spider(str):     source_code = requests.get(str)     plain_text = source_code.text     soup = beautifulsoup(plain_text, "html.parser")  # players elements in soup.find('table' , {'id' : 'stats'}).findall('a'):     names = elements.string     print(names)    str = input("enter query result url ")  bball_spider(str) 

you there, first let me mention since seems new python: shouldn't name variable str, because shadows built-in str class, that's modified in code shown below. important modification changed .findall('a') .findall('td',{'class':'left active'}), inspecting element can see names of players in <td> tag class left active. changed iterating var element instead of plural, makes more sense semantically speaking. note code posted not correctly idented, think formatting issue when pasted here.

import requests bs4 import beautifulsoup  def bball_spider(url):     source_code = requests.get(url)     plain_text = source_code.text     soup = beautifulsoup(plain_text, "html.parser")      # players     element in soup.find('table',{'id' : 'stats'}).findall('td',{'class':'left active'}):         names = element.string         print(names)  url = '''https://www.basketball-reference.com/play-index/psl_finder.cgi?request=1&match=single&type=totals&per_minute_base=36&per_poss_base=100&season_start=1&season_end=-1&lg_id=nba&age_min=0&age_max=99&is_playoffs=n&height_min=0&height_max=99&year_min=2017&year_max=2017&birth_country_is=y&as_comp=gt&as_val=0&pos_is_g=y&pos_is_gf=y&pos_is_f=y&pos_is_fg=y&pos_is_fc=y&pos_is_c=y&pos_is_cf=y&c1stat=fg3_pct&c1comp=gt&c1val=40&c2stat=fg3a&c2comp=gt&c2val=164&c3stat=dbpm&c3comp=gt&c3val=0&order_by=ws''' bball_spider(url) 

this print:

chris paul otto porter joe ingles 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -