Python写爬虫,得到了图片链接,怎样写入文件

2025-03-22 00:16:44
推荐回答(1个)
回答1:

img_req=urllib2.Request(Img_URL)
img_response=opener.open(img_req)
try:
     out=open('code','wb')
     #print img_response.read()
     out.write(img_response.read())
     out.flush()
     out.close()
     print 'get code success'
except IOError:
     print 'file wrong'