《乘风破浪的姐姐3》王心凌一骑绝尘,破收视率,多年后再次全网爆火,某音截止现在差不多3500W粉丝,五月份热门女星排名,吊打其它所有人,不愧是我女神!
但是这个热度,感觉她的歌曲和MV,已经离收费越来越近了,于是我连夜用Python把所有MV 和歌曲离线,今天先给大家分享MV的方法。
女神镇楼!
话不多说,我们开冲!
; 步骤分析
一、数据来源分析
1、首先我们确定自己的需求,什么网站,获取什么数据。
以酷我为例,直接打开酷我搜索王心凌,点击MV。
然后我们通过开发人员工具进行包分析,以分析我们想要的数据来自哪里。
[En]
Then we do package analysis through developer tools to analyze where the data we want comes from.
直接点击第一个,然后右键点击检查,或者直接按F12 打开开发者工具,然后点击network ,点击AII ,然后我们看到的是这样的页面。
此时没有数据,所以我们需要刷新它。
[En]
There is no data at this time, so we need to refresh it.
现在数据就出来了
每个视频都有自己的编号,我们可以在地址栏中看到。这段视频的编号是89622。
[En]
Each video has its own number, which we can see in the address bar. The number of this video is 89622.
我们在开发者工具找到对应的目录,在network → AII 里第一个就是。
或者直接点左上角的搜索工具,或者直接 Ctrl+f 打开搜索框,输入序号进行搜索。
第一种是,或者搜索相应的标题来查找相关数据。
[En]
The first is, or search the corresponding title to find the relevant data.
然后再这里找到我们需要的 Cookie 、Referer 、url 等等数据。
代码展示
本文中代码实现的四个基本步骤
[En]
The four basic steps of code implementation in this article
1. 发送请求, 模拟浏览器对于url网址发送请求 <专门定义函数来发送请求>
2. 获取数据, 获取网页源代码
3. 解析数据, 提取我们想要数据内容 <视频信息以及视频标题>
4. 保存数据, 把视频内容保存本地
</视频信息以及视频标题></专门定义函数来发送请求>
1、首先导入需要用的模块
import requests
import re
requests 是第三方模块,需要手动安装一下。
键盘按住 win+r 输入 cmd 确定,弹出命令提示符窗口,输入 pip install requests 回车安装即可。
不,你可以看到我的顶部文章,有一个特别的介绍,或者添加底部的文章直接联系我。
[En]
No, you can see my top article, there is a special introduction, or add the bottom of the article to contact me directly.
2、发送请求
模拟浏览器对于url网址发送请求
headers = {
'Cookie': '_ga=GA1.2.1259590012.1628168238; Hm_lvt_cdb524f42f0ce19b169a8071123a4797=1655356984; _gid=GA1.2.1126000694.1655356984; Hm_lpvt_cdb524f42f0ce19b169a8071123a4797=1655357023; _gat=1; kw_token=XBR2CWDG9IP',
'Host': 'www.kuwo.cn',
'Referer': 'http://www.kuwo.cn/search/list?key=%E9%99%88%E5%A5%95%E8%BF%85',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.84 Safari/537.36',
}
url = 'http://www.kuwo.cn/mvplay/89622'
response = requests.get(url=url, headers=headers)
Python学习交流群 279199867
所有这些数据都是在开发人员的工具中获得的。你还记得上面提到的步骤吗?
[En]
All these data are obtained in the developer’s tool. do you remember the steps mentioned above?
Cookie、Host 、Referer 、 User-Agent 这些数据找到后,直接复制下来,Referer是防盗链,没看到的话不用写。
url 在第一个
相应的标签需要放在引号中,才能将复制的内容更改为词典格式。
[En]
The corresponding tag needs to be in quotation marks to change the copied content into a dictionary format.
然后通过 response 对网站发送请求
print 打印一下
__
3、获取数据
html_data = response.text
print(html_data)
Python学习交流群 279199867
打印以查看获得的数据。
[En]
Print to see the data obtained.
4、解析数据
.*?匹配任意字符 \n 换行除外
video_url = re.findall('src:"(.*?)"}]', html_data)[0]
video_url = video_url.replace('\\u002F', '/')
video_data = requests.get(url=video_url).content
5、保存数据
with open('爱你.mp4', mode='wb') as f:
f.write(video_data)
你可以开始快乐地欣赏女神了!
[En]
You can begin to enjoy the goddess happily!
在这里,我只进行了一次获取、多个爬行和多个页面爬行。我专门录制了这段视频,可以在本文中获得。
[En]
Here I just made a single acquisition, multiple crawls and multi-page crawls. I specifically recorded the video, which can be obtained in this article.
Original: https://www.cnblogs.com/hahaa/p/16383541.html
Author: 轻松学Python
Title: 王心凌再次爆火,为了防止收费,我连夜用Python把她所有的MV离线
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/499315/
转载文章受原作者版权保护。转载请注明原作者出处!