Skip to content

Instantly share code, notes, and snippets.

@Loovelj
Created August 9, 2019 07:53
Show Gist options
  • Select an option

  • Save Loovelj/58fa948187c08ecfa784e639221d3d9b to your computer and use it in GitHub Desktop.

Select an option

Save Loovelj/58fa948187c08ecfa784e639221d3d9b to your computer and use it in GitHub Desktop.
根据url下载数据
import requests
import os
with open(r'D:\liujun\20-31.txt','r',encoding='utf-8') as f:
file_list=f.readlines()
for file in file_list:
file=file.replace('\n','')
base_name=os.path.basename(file)
try:
url =file
response = requests.get(url)
# 获取的文本实际上是图片的二进制文本
img = response.content
# 将他拷贝到本地文件 w 写 b 二进制 wb代表写入二进制文本
# 保存路径
path = os.path.join('D:\liujun\panpan_data',base_name)
with open(path, 'wb') as f:
f.write(img)
except Exception as ex:
print(ex)
print("--------出错继续----")
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment