Dec-15-2018, 08:10 PM
I am very much a newbie and I'm just trying to learn. Here is my code
09/03/18 Virginia Tech L 3-24 3:12 75,237 09/08/18 Samford W 36-26 3:51 72,239 09/15/18 @ 17 Syracuse L 7-30 3:37 37,457 09/22/18 Northern Ill. W 37-19 3:34 65,633 09/29/18 @ Louisville W 28-24 3:27 52,798 10/06/18 @ Miami (Fla.) L 27-28 4:01 65,490 10/20/18 Wake Forest W 38-17 3:34 67,274 10/27/18 2 Clemson L 10-59 3:47 68,403 11/03/18 @ North Carolina St. L 28-47 3:33 57,600 11/10/18 @ 3 Notre Dame L 13-42 3:22 77,622 11/17/18 Boston College W 22-21 3:31 57,274 11/24/18 10 Florida L 14-41 3:27 71,953 @ : Away, + : Neutral Site
My goal is to return the columns with date, opponent, and attendance (at least). The last row is immaterial and needs to be removed. It would also be good to learn how to create an additional column where if you see a @ in opponent the column says A, + is N, and neither is H.
The date and opponent names have classes in the table but attendance does not.
Appreciate any guidance. It's just a learning exercise.
import requests from bs4 import BeautifulSoup import csv url = 'http://www.cfbstats.com/2018/team/234/index.html' r = requests.get(url) soup = BeautifulSoup(r.text, 'html.parser') table = soup.findAll("table",{"class":"team-schedule"}) for row in table: tds = row.findAll('td') for td in tds: print(td.text)The results return but by line.
09/03/18 Virginia Tech L 3-24 3:12 75,237 09/08/18 Samford W 36-26 3:51 72,239 09/15/18 @ 17 Syracuse L 7-30 3:37 37,457 09/22/18 Northern Ill. W 37-19 3:34 65,633 09/29/18 @ Louisville W 28-24 3:27 52,798 10/06/18 @ Miami (Fla.) L 27-28 4:01 65,490 10/20/18 Wake Forest W 38-17 3:34 67,274 10/27/18 2 Clemson L 10-59 3:47 68,403 11/03/18 @ North Carolina St. L 28-47 3:33 57,600 11/10/18 @ 3 Notre Dame L 13-42 3:22 77,622 11/17/18 Boston College W 22-21 3:31 57,274 11/24/18 10 Florida L 14-41 3:27 71,953 @ : Away, + : Neutral Site
My goal is to return the columns with date, opponent, and attendance (at least). The last row is immaterial and needs to be removed. It would also be good to learn how to create an additional column where if you see a @ in opponent the column says A, + is N, and neither is H.
The date and opponent names have classes in the table but attendance does not.
Appreciate any guidance. It's just a learning exercise.