我想从这个网站上摘录视频。 http://www.jpopsuki.tv/video/Meisa-Kuroki---Bad-Girl/eec457785fba1b9bb35481f438cf35a7
我可以使用python访问它并获取整个html。但视频的网址是相对的,即如下所示:
<source src="/images/media/eec457785fba1b9bb35481f438cf35a7_1351466328.mp4" type="video/mp4" />
有没有办法使用python将其从网站上拉出来?
答案 0 :(得分:4)
找到here
下面的功能我认为这样做:
import requests
def download_file(url):
local_filename = url.split('/')[-1]
# NOTE the stream=True parameter
r = requests.get(url, stream=True)
with open(local_filename, 'wb') as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk: # filter out keep-alive new chunks
f.write(chunk)
#f.flush() commented by recommendation from J.F.Sebastian
return local_filename
download_file("http://www.jpopsuki.tv/images/media/eec457785fba1b9bb35481f438cf35a7_1351466328.mp4")