单词批量下载
import re
import requests
import os
with open ( '1.txt' , 'r' , encoding= "utf-8" ) as f1:
lines= f1. readlines( )
for line in lines:
foler_name= line. strip( )
url = "https://dict.youdao.com/dictvoice?audio=" + foler_name+ "&type=2"
res = requests. get( url= url) . content
with open ( foler_name + '.mp3' , mode= 'wb' ) as f:
f. write( res)
print ( foler_name+ "下载成功" )
B站视频爬取
import json
import subprocess
import requests
import re
headers= {
"User-Agent" : "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.5735.289 Safari/537.36" ,
"Cookie" : "buv8F391429; bmg_af_switch=1; bmg_src_def_domain=i1.hdslb.com; buvid_fp=ee1429752f177886082877472a9c0eea; browser_resolution=3434-1288" ,
"Referer" : "https://space.bilibili.com/700954976/video"
}
url= "https://www.bilibili.com/video/BV1mt421W73c"
res= requests. get( url= url, headers= headers)
html= res. text
html_text= re. findall( 'title="(.*?)" class' , html) [ 0 ]
html1= re. findall( '<script>window.__playinfo__=(.*?)</script>' , html) [ 0 ]
json_data= json. loads( html1)
audio_url= json_data[ "data" ] [ 'dash' ] [ 'audio' ] [ 0 ] [ 'baseUrl' ]
video_url= json_data[ "data" ] [ 'dash' ] [ 'video' ] [ 0 ] [ 'baseUrl' ]
audio_content= requests. get( url= audio_url, headers= headers) . content
video_content= requests. get( url= video_url, headers= headers) . content
with open ( "video\\" + html_text+ '.mp3' , mode= "wb" ) as audio:
audio. write( audio_content)
with open ( "video\\" + html_text+ '.mp4' , mode= "wb" ) as video:
video. write( video_content)
cmd= f"ffmpeg -i video\\ { html_text} .mp4 -i video\\ { html_text} .mp3 -c:v copy -c:a aac -strict experimental video\\ { html_text} 1.mp4"
subprocess. run( cmd, shell= True )