我对此进行编码以下载一些网站。但它不能没有错误地运行
可以下载页面,但不是打印“下载完成”,而是打印以下错误:
Traceback (most recent call last):
File "F:\Copy\Desktop\gethanhan.py", line 28, in <module>
con = urllib.urlopen(my_url[j]).read()
File "C:\Python27\lib\urllib.py", line 87, in urlopen
return opener.open(url)
File "C:\Python27\lib\urllib.py", line 208, in open
return getattr(self, name)(url)
File "C:\Python27\lib\urllib.py", line 463, in open_file
return self.open_local_file(url)
File "C:\Python27\lib\urllib.py", line 477, in open_local_file
raise IOError(e.errno, e.strerror, e.filename)
IOError: [Errno 2] : ''
我测试了几个小时。但我仍然找不到问题。这是代码:
......
#use a list which have urls to download url pages
j = 0
while j<50:
con = urllib.urlopen(my_url[j]).read()
filename = my_url[j][-26:]
print 'Downloading'
full_path ='F:/Copy/Desktop/kankan/' + str(j) + '.html'
#ERROR appears in here:
open(full_path,'w+').write(con)
j += 1
else:
print 'Download finished'