ติดตั้ง requests
โค้ด: เลือกทั้งหมด
pip install requests
โค้ด: เลือกทั้งหมด
import requests
โค้ด: เลือกทั้งหมด
url='http://127.0.0.1:5000/video/content.mp4'
req = requests.get(url)
โค้ด: เลือกทั้งหมด
vdo_name = url.split('/')[-1]
โค้ด: เลือกทั้งหมด
head_req=req.headers
โค้ด: เลือกทั้งหมด
for k, v in head_req.items():
โค้ด: เลือกทั้งหมด
if k == 'Content-Type':
โค้ด: เลือกทั้งหมด
v = v.split('/')
if v[0] == 'video':
โค้ด: เลือกทั้งหมด
path_donw_vdo =vdo_name
with open(path_donw_vdo, 'wb') as f:
f.write(req.content)
print 'Download '+vdo_name+' success'
จากนั้นสังเกตได้ว่ามีไฟล์วีดีโอเพิ่มเข้ามา
ไฟล์ python รวม
โค้ด: เลือกทั้งหมด
import requests
url='http://127.0.0.1:5000/video/content.mp4'
req = requests.get(url)
vdo_name = url.split('/')[-1]
head_req=req.headers
for k, v in head_req.items():
if k == 'Content-Type':
# print k, v
v = v.split('/')
if v[0] == 'video':
path_donw_vdo =vdo_name
with open(path_donw_vdo, 'wb') as f:
f.write(req.content)
print 'Download '+vdo_name+' success'
อ้างอิง
https://stackoverflow.com/questions/16694907/download-large-file-in-python-with-requests
https://www.codementor.io/aviaryan/downloading-files-from-urls-in-python-77q3bs0un
https://www.geeksforgeeks.org/downloading-files-web-using-python/