import requests # 替换为你的目标CSV文件下载链接 url = 'http://example.com/path/to/data.csv' # 定义保存文件的本地路径和文件名 file_path = 'local_data.csv' # 发送GET请求到目标URL response = requests.get(url, stream=True) # 检查请求是否成功 if response.status_code == 200: # 使用二进制写模式打开文件 with open(file_path, 'wb') as file: # 分块读取响应内容并写入文件,避免内存占用过大 for chunk in response.iter_content(chunk_size=8192): if chunk: file.write(chunk) print(f'CSV文件已保存到 {file_path}') else: print(f'下载失败,状态码: {response.status_code}')
python从某网址下载csv文件(未)
最新推荐文章于 2024-05-30 11:43:13 发布