from urllib.request import urlopen from io import StringIO import csv data = urlopen("http://pythonscraping.com/files/MontyPythonAlbums.csv").read().decode('ascii','ignore') # ignore:忽略 dataFile = StringIO(data) # 封装称StringIO对象,当作文件处理 dictReader = csv.DictReader(dataFile) # DictReader将第一行的字段Name和Year作为后面的数据的key,成为一个个字典 for row in dictReader: print(row)