0
프로그래밍 기술을 향상시키면서 시험 웹 사이트에서 과거 논문을 일괄 다운로드하려고합니다. 나는 많은 것을 연구했고 이것이 왜 작동하지 않는지 모릅니다.여기에 왜 FileNotFoundException이 발생합니까?
오류 :
Downloading C:\Users\Azmat\Desktop\Practise Exams\Biology\January 2012 Question Paper.pdf
Traceback (most recent call last):
File "testDownloader.py", line 31, in <module>
with open(filename, 'w+') as code:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Azmat\\Desktop\\Practise Exams\\Biology\\January 2012 Question Paper.pdf'
내 코드 :
import urllib.request, urllib.parse, urllib.error
years = [12, 13]
months = ["JAN", "JUN"]
subjects = ["BL", "CH", "PH"]
files = ["QP", "W-MS", "WRE"]
sub = {
'BL': 'Biology',
'CH': 'Chemistry',
'PH': 'Physics',
}
mon = {
'JAN' : 'January',
'JUN' : 'June',
}
fil = {
'QP' : 'Question Paper',
'W-MS' : 'Mark scheme',
'WRE' : "Examiner's report"
}
for year in years:
for month in months:
for subject in subjects:
for file in files:
url =('http://filestore.aqa.org.uk/subjects/AQA-%s1HP-%s-%s%d.PDF' % (subject, file, month, year))
filename = 'C:\\Users\\Azmat\\Desktop\\Practise Exams\\' + sub[subject] + '\\' + mon[month] + ' 20%d ' % year + fil[file] + '.pdf'
print("Downloading " + filename)
f = urllib.request.urlopen(url)
data = f.read()
with open(filename, 'w+') as code:
code.write(data)
고맙습니다. 문제가 해결되었습니다. – Injustice