Created
August 10, 2017 10:37
-
-
Save gt11799/30d8e89d96352ac178f7e0e69fe06bfb to your computer and use it in GitHub Desktop.
下载图片的脚本
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # coding: utf-8 | |
| import csv | |
| import requests | |
| def save_pic(filename, content): | |
| with open(filename, 'wb') as f: | |
| f.write(content) | |
| def get_pic(url, filename): | |
| response = requests.get(url) | |
| if response.status_code == 200: | |
| save_pic(filename, response.content) | |
| else: | |
| print('error! %s' % response.status_code) | |
| def main(): | |
| with open('1.csv') as f: | |
| reader = csv.reader(f) | |
| # 丢掉第一行 | |
| print reader.next() | |
| result = [] | |
| count = 0 | |
| for item in reader: | |
| count += 1 | |
| print count, item | |
| get_pic(item[0], '%s.jpg' % count) | |
| if __name__ == '__main__': | |
| main() | |
| # save_pic('1.txt', 'content') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment