I can't get the output I have scraped using Beautiful Soup to write to a CSV file. I have it in the format but I like when I print, but cannot get it to write to a csv like that.
I've tried several variations of the csv write function but most of the things I can find online are for a given list or dictionary, none of which is the format of my data. Maybe I need to make it a list somehow?
rank = (pga_text)[0]
player = (pga_text)[2]
sg_p = (pga_text)[4]
pga_file = rank + ", " + player + ", " + sg_p
print(pga_file)
myfile = open(r'C:\Users\Walsh\Documents\Python Scripts\pga.csv', 'w')
with myfile:
myfields = [rank]
writer = csv.writer(myfile)
writer.writerow(pga_file)
a.close()
As mentioned, the output from the print is in the format I wanted:
1, Justin Harding, 1.000
2, Andrew Putnam, .952
3, Dominic Bozzelli, .821
4, Graeme McDowell, .789
but nothing writes to the actual file.