使用如下方法,图片下载后不能打开:
img = urllib2.urlopen(<span style="color: rgb(128, 0, 0); font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit; font-size: 14px; line-height: 17.8048000335693px; background-color: transparent;">'http://example.com/img.png'</span>)
fname = 1.jpg'
with open(fname, 'wb') as localFile:
localFile.write(img.read())
使用如下方法,图片下载正常:
fname = '1.jpg'
urllib.urlretrieve(<span style="color: rgb(128, 0, 0); font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit; font-size: 14px; line-height: 17.8048000335693px; background-color: transparent;">'http://example.com/img.png'</span>, fname)
urllib. urlretrieve函数的作用是直接将远程数据下载到本地