示例代码:
import os
import requests
import pandas as pd
# 发送get请求,获取网页数据(tsv文件)
url = 'https://raw.githubusercontent.com/udacity/new-dand-advanced-china/master/%E6%95%B0%E6%8D%AE%E6%B8%85%E6%B4%97/WeRateDogs%E9%A1%B9%E7%9B%AE/image-predictions.tsv'
res = requests.get(url)
# 创建文件夹
folder_name = 'data'
if not os.path.exists(folder_name):
os.makedirs(folder_name)
# 输出到文件
file_name = url.split('/')[-1]
with open(os.path.join(folder_name, file_name), mode='wb') as file:
file.write(res.content)
# 再用pandas读取tsv文件
pd.read_table(os.path.join(folder_name, file_name))