前言
嗨喽,大家好呀~这里是爱看美女的茜茜呐
又到了学Python时刻~
第三方模块:
- requests >>> pip install requests
环境介绍:
-
python 3.8 解释器 -
pycharm 编辑器 -
ffmpeg 音视频合成软件
软件点击 蓝色字体 自取
如果安装python第三方模块:
-
win + R 输入 cmd 点击确定, 输入安装命令 pip install 模块名 (pip install requests) 回车 -
在pycharm中点击Terminal(终端) 输入安装命令
如何配置pycharm里面的python解释器?
-
选择file(文件) >>> setting(设置) >>> Project(项目) >>> python interpreter(python解释器) -
点击齿轮, 选择add -
添加python安装路径
pycharm如何安装插件?
-
选择file(文件) >>> setting(设置) >>> Plugins(插件) -
点击 Marketplace 输入想要安装的插件名字 比如:翻译插件 输入 translation / 汉化插件 输入 Chinese -
选择相应的插件点击 install(安装) 即可 -
安装成功之后 是会弹出 重启pycharm的选项 点击确定, 重启即可生效
代码实现:
-
发送请求 -
获取数据 -
解析数据 -
保存数据
代码
import requests
import re
import json
import base64
headers = {
'cookie': 'MONITOR_WEB_ID=d60c8d6b-f9fd-4b42-87ed-d7f0dd177d84; s_v_web_id=verify_l6c4goey_Fh9d4TZc_AmaK_4BRa_BLeh_B5vXZ6H781yo; passport_csrf_token=2dbecb46b188ac34405333e002497f32; passport_csrf_token_default=2dbecb46b188ac34405333e002497f32; BD_REF=1; support_webp=true; support_avif=true; sid_guard=5a594d8ffa24987c9089e04fae66e393%7C1662550605%7C3024000%7CWed%2C+12-Oct-2022+11%3A36%3A45+GMT; uid_tt=5384c3b25787b6d639046fa229fab410; uid_tt_ss=5384c3b25787b6d639046fa229fab410; sid_tt=5a594d8ffa24987c9089e04fae66e393; sessionid=5a594d8ffa24987c9089e04fae66e393; sessionid_ss=5a594d8ffa24987c9089e04fae66e393; sid_ucp_v1=1.0.0-KDgwOGQ4MGI4OWY4YzdiMGRhODVkOWNhY2RhMjlhMWFkNzM4MWJlMjUKFAjo5IrYFxDNhOKYBhgYIAw4CEAFGgJsZiIgNWE1OTRkOGZmYTI0OTg3YzkwODllMDRmYWU2NmUzOTM; ssid_ucp_v1=1.0.0-KDgwOGQ4MGI4OWY4YzdiMGRhODVkOWNhY2RhMjlhMWFkNzM4MWJlMjUKFAjo5IrYFxDNhOKYBhgYIAw4CEAFGgJsZiIgNWE1OTRkOGZmYTI0OTg3YzkwODllMDRmYWU2NmUzOTM; __ac_signature=_02B4Z6wo00f01HEALmwAAIDBEgruBOEFt9hxICrAAH9gv9rvSZZuqiB0o0tboJ0vQ97xgpdUySya065pz20yeFgC1Yrz35jV.b8cHjdbRm-i7w8W-jifqtBdIA0LFeUHtfCY4.NYmLy13hutae; _tea_utm_cache_1300=undefined; odin_tt=704235ed5afa6910dc0b5ffb994bb5d3daf9c0591b868ff9da14f5393de8bc2fffc97916402e1ff35ecb9fb0af2a7e08; tt_scid=CRHRc1Kwkz.aeOXFeILnmZSqNYZcf7DM.TjaByz0zHNUap-3q9c0l9byzlYzTrHG0a81; ttwid=1%7CaXGLP4hVSb3AgEBeaA89sdnboUoIVkitcI14pne1BV4%7C1662550872%7Cafe39b6a79fbdc545c4dfcd0676cf3207ed4522534434f8c08d06cc62d22f819; ixigua-a-s=3; __ac_nonce=063188a2b001d4fe7a4be; msToken=TM5cvaKIWDxYdeBOLwcZ_yYIufnXuW0ubPWwbYXt12vFjzpdwIaSzwF6Ai8vmmvh6OQteexulP9-f2LGb15nyB42UmduwGvQBWOUgC8Kw3a1PZ-AeYVjSL12CEGhGzg=',
list_url = 'https://www..com/api/videov2/author/new_video_list?to_user_id=105191269248&offset=30&limit=30&maxBehotTime=1597400514&order=new&isHome=0&msToken=aM8EWMWtHK4rLnnKWyb4MiUMbCo4P3e0FWO-HlKbQJL00ZxEmyzUWRVqcBhGbB3XxZmXMOjxlyApUDp8Z61SeuhL4ulGttJj86D7sI3Ssm-UW8jWre4_hj_R6EJOu74=&X-Bogus=DFSzswVLuvtANydASQJoVKXAIQ58&_signature=_02B4Z6wo000016eh55gAAIDCxKsn8AABWN-noeMAAIr5sacqPdq.nIwq052pRqOBr75PmVJ7xfDp9CRkNzQg3K5X7u-juF8axvWLBstGC4JwHVTiJ2yuZnXxL.H3DlOGWPDJFGcPX.7K2BRZ5d'
这里嘚标志性网址删了,可以自己加一下哦~
继续我们嘚代码~嘿嘿
response = requests.get(url, headers=headers)
response.encoding = 'utf-8'
html_data = response.text
json_str = re.findall('_SSR_HYDRATED_DATA=(.*?)</script>', html_data)[0]
json_str = json_str.replace('undefined', 'null')
json_dict = json.loads(json_str)
title = json_dict['anyVideo']['gidInformation']['packerData']['video']['title']
main_url = json_dict['anyVideo']['gidInformation']['packerData']['video']['videoResource']['normal']['video_list']['video_4']['main_url']
video_url = base64.b64decode(main_url).decode()
print(title)
print(video_url)
video_data = requests.get(video_url).content
with open(f'mp4//{title}.mp4', mode='wb') as f:
f.write(video_data)
效果
文章看不懂,我专门录了对应的视频讲解,本文只是大致展示,完整代码和视频教程点击下方蓝字
点击 蓝色字体 自取,我都放在这里了。
尾语 💝
感谢你观看我的文章呐~本次航班到这里就结束啦 🛬
希望本篇文章有对你带来帮助 🎉,有学习到一点知识~
躲起来的星星🍥也在努力发光,你也要努力加油(让我们一起努力叭)。
最后,博主要一下你们的三连呀(点赞、评论、收藏),不要钱的还是可以搞一搞的嘛~
不知道评论啥的,即使扣个6666也是对博主的鼓舞吖 💞 感谢 💐
|