我正在尝试此代码:
import requests
from bs4 import BeautifulSoup
import csv
def writetocsv(l):
#convert the set to the list
b = list(l)
print (b)
with open("eggs.csv",'w') as f:
w = csv.writer(f)
for value in b:
w.writerow([value])
url = 'http://espn.go.com/nhl/teams'
r = requests.get(url)
soup = BeautifulSoup(r.content)
hockey_teams = []
for l in soup.findAll("a",{"class":"bi"}):
hockey_teams.append(l.get_text())
writetocsv(hockey_teams)
它的打印方式如下: 1芝加哥黑鹰队 2 3科罗拉多雪崩 怎么能让它不跳过行??
答案 0 :(得分:1)
我找到了解决方案:
with open("nhlteams.csv",'w',newline='',) as f:
w = csv.writer(f, delimiter=',')
它是在newline =“”它是必须使它不跳过