抓取网页音频(mp3设置网站服务端口(默认端口)是我的网站地址)
优采云 发布时间: 2022-04-10 15:05抓取网页音频(mp3设置网站服务端口(默认端口)是我的网站地址)
抓取网页音频可能是一件令人头疼的事情,你可能需要n多的服务器。由于空间容量有限,自然可以使用网页版的搜索引擎来满足你寻找音频文件的需求。flask是一个开源轻量级web框架,一些非常常用的web框架如scrapy等一般都采用flask来做web框架,作为一个web框架,它提供了丰富的webapi,你不用搭建自己的服务器,而是使用flask,只需把你需要的模板写在flask中即可。
今天分享一个很简单的对mp3音频文件的操作,下面我会*敏*感*词*教你在本地运行以下两个命令:flask-mloginlocation设置网站服务端口(默认端口是21)importloginlocationimportloginlocationpwd=loginlocation.pwdimportrequestsres=requests.get('//login')res=res.textez_now_code='210346'forez_now_codeinres:print(ez_now_code)2.读取下载到本地的mp3音频文件在flask中我们经常写一些api方法,用来操作网页或者app中的某个对象,而对于web框架来说,这些api方法的每一个属性都可以通过flask框架自带的api接口的方式获取到,其中设置get(url)和post(path)方法可以达到读取文件的目的,下面我会逐一介绍一下。
importloginlocationimportrequestsres=requests.get('/')loginlocation.post(url,path='/')string=res.read()string=string[5]res.send(string)在以上两个命令中,res.read()方法有一个参数,即你需要进行解析的音频地址,在下面代码中使用的是我的网站地址,youtube:,然后就可以读取并传给loginlocation.post去操作。
importloginlocationimportrequestsdefhttp_record(proxies,data):url='/'loginlocation.post(url,data={'app':'flask'})response=loginlocation.post(url,data={'data':url})response=response.textreturnresponseget_single_music.pyimportloginlocationimportrequestsimportreimportjsonimporttimefromflask_webimportflaskfromparseimportload_by_postfromparseimportsequenceimportrequestsimporttime#importthemusicfromflask_musicimportrequests#importtheboundariesfromsong_songimportsong_song#importtheporttagfromflask_musicimportrequestsfrombs4importbeautifulsoup#importbase64importfsimportos#importformat.request,urllib#importformat.request,urllib。