다음 코드는 모든 반복을 다음 코드에 추가합니다. 모든 파일은 약 50 명의 플레이어 여야하지만 파일 이름 팀 1은 50이고 파일 이름 팀 2는 100 (team1 + team2) 등입니다. 연도 + 팀의 1 회 반복만으로 개별 파일을 생성하려면 어떻게해야합니까?
from nfl_fun import make_soup
import os
from itertools import islice
import csv
from datetime import datetime
years = [2019,2018,2017,2016,2015]
year = datetime.now().year
if year not in years:
years.append(year)
linkname = ""
with open("teamlink.csv") as tl:
for row in islice(csv.reader(tl), 1, None):
for season in years:
rowlink = f"https://www.footballdb.com/{row[0]}/roster/{season}"
soup = make_soup(rowlink)
try:
for boot in soup.findAll('b'):
for link in boot.findAll('a'):
if link.has_attr('href'):
linkname = linkname + "\n" + (link.attrs['href'])[1:]
userfile = f"{rowlink[37:-12]}-{season}"
header="Links"
file = open(os.path.expanduser(f"{userfile}.csv"), "wb")
file.write(bytes(header, encoding="ascii", errors='ignore'))
file.write(bytes(linkname, encoding="ascii",errors='ignore'))
file.close()
except:
continue
linkname
팀을 변경할 때마다 재설정해야 합니다.
linkname = ""
후 file.close()
또는 비슷한 것.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다