Dec-17-2018, 04:40 PM
(This post was last modified: Dec-17-2018, 06:39 PM by Axel_Erfurt.)
He means the last line in the table
that' why I used
Quote:@ : Away, + : Neutral Site
that' why I used
_len = len(datasets) for x in range(_len -1):You do not need CSV writer for the csv file.
from urllib.request import urlopen from bs4 import BeautifulSoup as bsoup url = 'http://www.cfbstats.com/2018/team/234/index.html' ofile = urlopen(url) soup = bsoup(ofile, "html.parser", from_encoding='utf-8') soup.prettify() table = soup.find("table", attrs={"class":"team-schedule"}) datasets = [] mytable = table.find_all("tr") for row in mytable: text = str(row.get_text()).split('\n') datasets.append(text) mypath = '/tmp/test_cfbstats.csv' with open(mypath, 'w') as stream: _len = len(datasets) for x in range(_len -1): t = datasets[x] myrow = [t[1], t[2], t[5]] t = "\t".join(myrow) print(t.expandtabs(22)) stream.write(t + "\n") stream.close()