import requests
import json
import re
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36'
}
def chenk_title(title):
'''替换非法字符窜'''
pattern = re.compile(r"[\/\\\:\*\?\"\<\>\|]")
new_title = re.sub(pattern,"_",title)
return new_title
def get_html(link):
print("======正在获取的数据的目标网址:",link)
resp = requests.get(link,headers=headers).text
mp4_list = json.loads(resp) # 数据转换
return mp4_list
def save_parser_hrml(mp4_list):
scr_list = mp4_list['content']['list']
for scr in scr_list:
name_list = scr['title']+'.mp4'
link_list = scr['playurl']
new_name = chenk_title(name_list)
print("正在下载",new_name)
mp4 = requests.get(link_list,headers=headers).content
with open(r'C:\Users\DELL\Desktop\python_wd\shipin\六间房\\'+ new_name ,'wb')as f:
f.write(mp4)
print("下载完成。。。。。。\n")
def main():
for page in range(1,5):
link = 'https://v.6.cn/minivideo/getlist.php?act=recommend&page={}&pagesize=20'.format(page)
mp4_list = get_html(link)
save_parser_hrml(mp4_list)
if __name__ == '__main__':
main()
六房短视频获取 -函数
最新推荐文章于 2023-12-28 16:19:51 发布